Repository navigation
Conversation
`flame run --deopt` records the V8 deoptimizations that happen while the CPU profiler runs and stores them in the CPU profile as a `v8-deopts` JSON comment, which react-pprof renders as markers, tooltip entries and a details panel. The markdown report gets a "V8 Deoptimizations" section with the functions that have actionable deopts, their share of the profile and an explanation of each reason. V8 does not reliably write `code-deopt` records to its log while a CPU profile is being recorded, so deopts are read from V8's deopt traces: the process starts with --trace-deopt-verbose redirected to a temporary file, and the preload turns tracing off at startup and back on only during profiling windows (including SIGUSR2 toggles). Requires react-pprof with deopt support (^1.6.0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sfj4nDTRSqdZpTPUFfHCyZ
This branch has not been deployed
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.
Adds
flame run --deopt. It records the V8 deoptimizations that happen while the CPU profiler runs and stores them in the CPU profile. The flamegraph shows them (markers, tooltip, details panel) and the markdown report gets a new section.Depends on platformatic/react-pprof#54. That PR does the rendering and provides the reason catalog. This PR bumps
react-pprofto^1.6.0, assuming that's the release that ships it, and doesn't updatepackage-lock.jsonbecause that version isn't published yet. CI will fail until it is; after the release, runnpm installto update the lockfile.How it works
I first tried V8's log (
--log-deopt, toggled at runtime). That works without a profiler, but V8 does not reliably writecode-deoptrecords while a CPU profile is being recorded. With @datadog/pprof running, a test with 4 deopts logged 1; with the inspector profiler it logged 0. The[bailout …]traces are still emitted, so this PR reads those instead:startProfiling({ deopt: true })starts the process with--trace-deopt-verbose --redirect-code-traces --redirect-code-traces-to=<tmpdir>/deopt-trace.txt.;;; deoptimize at <file:line:col>).preload.jsturns tracing off immediately. It turns it back on when the CPU profiler starts and off when it stops, so SIGUSR2 windows work too. Toggling works on Node 22, 24 and 26.lib/deopt.jsparses the part of the trace file written during the window. For each deopt it takes the reason, the bailout kind, the function name and the position. It then assigns the deopt to a function in the profile using the outermost (non-inlined) position and the function name, picking the closest function start at or before that position.Function.startLineempty and stores the start line in the location, so the matcher uses that. It's the same line react-pprof uses for frames, which makes the match exact.v8-deoptsJSON comment in the.pb, soflame generateshows the deopts too. The temporary directory is deleted when the child process exits.Markdown
When a CPU profile has deopt data,
generateMarkdown(and the preload's copy of it) adds a V8 Deoptimizations section:Tiering events (OSR, insufficient type feedback) are counted, but their functions aren't listed.
Limitations
--delay=until-started, that includes the first synchronous run of the script;--delay=nonecaptures it.Tests
test/deopt.test.js:flame run --deopt --delay=nonetest, which checks that deopts are attached to the script's functions, that no[bailoutlines reach stdout, and that the markdown section is writtennode_modules. With the publishedreact-pprof@1.5.1, the markdown tests fail because the catalog isn't there.🤖 Generated with Claude Code
https://claude.ai/code/session_01Sfj4nDTRSqdZpTPUFfHCyZ