Skip to content

Commit

Permalink
Fix CPU profiler latency (#1658)
Browse files Browse the repository at this point in the history
The current profile must be stopped AFTER the next begins. This is because V8 will
tear down the symbolizer thread when the active profile count reaches zero. This
means the next profile started will spin up a new symbolizer thread. When this
thread starts it streams in all the JIT location information which could block the
JavaScript thread for a significant length of time.
  • Loading branch information
Qard committed Oct 25, 2021
1 parent 56c67f5 commit 61ebb1b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/dd-trace/src/profiling/profilers/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class NativeCpuProfiler {

profile () {
if (!this._stop) return
const profile = this._stop()
// Next profile MUST be started before previous ends otherwise V8 will tear
// down the symbolizer thread and start a new one when the next one starts.
const stop = this._stop
this._record()
return profile
return stop()
}

encode (profile) {
Expand Down

0 comments on commit 61ebb1b

Please sign in to comment.