diagnostics_channel: lazily create tracing context - #65513
Open
RomainLanz wants to merge 1 commit into
Open
Conversation
Default parameters are evaluated before the function body, so the tracing context is allocated before the no-subscriber fast path. Initialize it only for subscribed traces. Preserve method arity with an undefined default and preserve explicit null behavior. Add focused regression coverage and reusable TracingChannel benchmarks. Signed-off-by: Romain Lanz <romain.lanz@pm.me>
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65513 +/- ##
==========================================
+ Coverage 90.15% 90.16% +0.01%
==========================================
Files 751 751
Lines 253514 253557 +43
Branches 47746 47774 +28
==========================================
+ Hits 228563 228630 +67
+ Misses 16203 16195 -8
+ Partials 8748 8732 -16
🚀 New features to boost your workflow:
|
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.
Note
AI assistance was used to investigate this issue and draft parts of the
implementation, tests, benchmarks, and PR description. I reviewed and
verified the final changes and benchmark results.
Hey! 👋🏻
While benchmarking our HTTP router, I noticed that manually checking whether a diagnostics channel had subscribers before tracing an operation improved performance.
That felt unexpected, so I dug deeper. It turns out that
TracingChannel.traceSync()andtracePromise()create their default context before checking whether any tracing channel has subscribers.As a result, calls without an explicit context allocate an object even when they immediately take the no-subscriber fast path.
This PR moves the default-context creation after the subscriber check. It also adds focused tests and benchmarks to verify the behavior and measure the performance impact.
Benchmarks
The comparison used two release builds, 30 alternating runs per configuration,
n=3,000,000, andbenchmark/compare.js --analyze.traceSynctraceSyncundefinedtracePromisetracePromiseundefinedAll four improvements have
***confidence (p < 0.001). No statisticallysignificant regressions were observed for explicit-context or subscribed
control cases.
The comparison can be reproduced with: