-
Notifications
You must be signed in to change notification settings - Fork 3
Store sampling context in ContinuationPreservedEmbedderData #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5b796ea
to
1b15c3a
Compare
1b15c3a
to
3decb46
Compare
bfa23b5
to
32b2170
Compare
32b2170
to
9f398f2
Compare
9f398f2
to
965a627
Compare
965a627
to
0c1791e
Compare
a2384e5
to
bb0bc2d
Compare
0c1791e
to
8f88f3d
Compare
@@ -66,6 +66,7 @@ export interface TimeProfilerOptions { | |||
withContexts?: boolean; | |||
workaroundV8Bug?: boolean; | |||
collectCpuTime?: boolean; | |||
useCPED?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8f88f3d
to
717f17b
Compare
3c86526
to
79992a0
Compare
717f17b
to
2b9041d
Compare
Overall package sizeSelf size: 1.62 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | source-map | 0.7.4 | 226 kB | 226 kB | | pprof-format | 2.1.0 | 111.69 kB | 111.69 kB | | p-limit | 3.1.0 | 7.75 kB | 13.78 kB | | delay | 5.0.0 | 11.17 kB | 11.17 kB | | node-gyp-build | 3.9.0 | 8.81 kB | 8.81 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
BenchmarksBenchmark execution time: 2025-06-25 12:14:59 Comparing candidate commit 4916ae7 in PR branch Found 4 performance improvements and 0 performance regressions! Performance is the same for 88 metrics, 28 unstable metrics. scenario:profiler-heavy-load-no-wall-profiler-22
scenario:profiler-light-load-no-wall-profiler-18
scenario:profiler-light-load-no-wall-profiler-22
scenario:profiler-light-load-no-wall-profiler-24
|
2b9041d
to
c475e2f
Compare
9ba3bf1
to
9c4090e
Compare
…preserved embedder data
Also optimize away some setting of null/undefined as context
34b19c4
to
5b06bbe
Compare
bindings/profilers/wall.cc
Outdated
@@ -59,6 +58,89 @@ using namespace v8; | |||
|
|||
namespace dd { | |||
|
|||
class SignalMutex { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sounds more like a Guard or a Lock
bindings/profilers/wall.cc
Outdated
|
||
ContextPtr Get() const { return context; } | ||
|
||
friend class WallProfiler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Why not make methods public instead ?
bindings/profilers/wall.cc
Outdated
|
||
// This class is used to update the context count metric when it goes out of | ||
// scope. | ||
class ContextCountMetricUpdater { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you could use a defer instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work !
- SignalMutex -> SignalGuard - Use defer instead of ContextCountMetricUpdater - make PersistentContextPtr methods public instead of declaring a friend class
🚀 |
What does this PR do?:
Moves profiler's sampling context into the V8 isolate's
ContinuationPreservedEmbedderData
(CPED.) In fact, moves it into a private symbol-keyed property within the object as Node.js version 24 and later will storeAsyncContextFrame
objects in the CPED.Motivation:
Before this change, we rely on async_hooks in dd-trace-js to update the sampling context on every context switch. It is both somewhat costly to do this on every async context switch and we should also migrate away from async hooks, as profiling is their last user, they'll be deprecated in Node, and they bring their own set of performance overhead by using them.
This PR comes with a document explaining the design in it.
Additional Notes:
The code using this in
dd-trace-js
'wall.js
sets the context onAsyncLocalStorage.{enterWith|run}
, and thebefore
callback ofAsyncHooks.createHook
. With CPED storage enabled, we can eliminate thebefore
callback and "only" keep theAsyncLocalStorage.{enterWith|run}
callbacks – they are the minimum amount of instrumentation needed for the feature to work correctly then.This branch can be tested with the same-named branch in dd-trace-js.
Jira: PROF-11771