perf(http/prom): avoid oneshot channel for request duration start time#4448
Open
perf(http/prom): avoid oneshot channel for request duration start time#4448
Conversation
RecordRequestDuration knows the start time at call() time, whereas RecordResponseDuration defers it until the request body flushes. The latter needs async delivery from the request body wrapper, but the former is known synchronously. Replace the shared oneshot::Receiver<Instant> in ResponseState with an enum supporting both immediate and deferred start times, removing one heap allocation per request. Signed-off-by: Alejandro Martinez Ruiz <amr@buoyant.io>
cratelyn
approved these changes
Mar 6, 2026
cratelyn
reviewed
Mar 6, 2026
| let state = self.labeler.mk_stream_labeler(&req).map(|labeler| { | ||
| let (tx, start) = oneshot::channel(); | ||
| tx.send(time::Instant::now()).unwrap(); | ||
| let start = super::StartTime::Known(Some(time::Instant::now())); |
Member
There was a problem hiding this comment.
🏃💨
this is an astute observation. thank you for opening this, @unleashed!
cratelyn
reviewed
Mar 6, 2026
| pub(crate) enum StartTime { | ||
| /// Start time is already known. | ||
| Known(Option<time::Instant>), | ||
| /// Start time will be sent when the request body finishes streaming |
Member
There was a problem hiding this comment.
Suggested change
| /// Start time will be sent when the request body finishes streaming | |
| /// Start time will be sent when the request body finishes streaming. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RecordRequestDuration knows the start time at call() time, whereas RecordResponseDuration defers it until the request body flushes. The latter needs async delivery from the request body wrapper, but the former is known synchronously.
Replace the shared oneshot::Receiver in ResponseState with an enum supporting both immediate and deferred start times, removing one heap allocation per request.