Skip to content

Add necessary flags to dump optimized inlining info and fix walltime marker placement#83

Merged
GuillaumeLagrange merged 6 commits into
mainfrom
cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information
Jun 22, 2026
Merged

Add necessary flags to dump optimized inlining info and fix walltime marker placement#83
GuillaumeLagrange merged 6 commits into
mainfrom
cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information

Conversation

@GuillaumeLagrange

Copy link
Copy Markdown
Contributor

No description provided.

Add --perf-prof, --log-code, --no-log-source-code, --no-logfile-per-isolate
and --logfile to getV8Flags in walltime mode. --perf-prof writes the jitdump
samply uses to symbolicate JIT'd JS; --log-code writes the code log whose
inlining map lets the symbolicating recover TurboFan/Maglev inlined frames the
jitdump alone collapses. Source-code logging is left off to keep the log small.

Refs COD-2821, COD-2822
@GuillaumeLagrange GuillaumeLagrange force-pushed the cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information branch from 0b43ff4 to e07237e Compare June 18, 2026 15:26
@codspeed-hq

codspeed-hq Bot commented Jun 18, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 74.17%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 23 improved benchmarks
❌ 23 regressed benchmarks
✅ 180 untouched benchmarks
🆕 12 new benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory switch 2 1 B 384 B -99.74%
Memory switch 2 1 B 384 B -99.74%
Memory test_iterative_fibo_100 1 B 264 B -99.62%
Memory test_iterative_fibo_10 1 B 264 B -99.62%
Memory test_recursive_cached_fibo_20 1 B 264 B -99.62%
Memory test_recursive_cached_fibo_20 1 B 264 B -99.62%
Memory test_recursive_cached_fibo_30 1 B 264 B -99.62%
Memory test_iterative_fibo_100 1 B 264 B -99.62%
Memory test sync baz 100 1 B 264 B -99.62%
Memory test_recursive_cached_fibo_30 1 B 264 B -99.62%
Memory switch 2 1 B 264 B -99.62%
Memory test sync baz 100 1 B 264 B -99.62%
Memory fibo 30 19 B 531 B -96.42%
Memory test_recursive_fibo_20 19 B 264 B -92.8%
Memory test_recursive_fibo_20 19 B 264 B -92.8%
Simulation test_recursive_fibo_10 145.2 µs 282.2 µs -48.56%
Simulation switch 2 11.2 µs 21.5 µs -47.96%
Memory test sync baz 10 385 B 648 B -40.59%
Memory test sync baz 10 385 B 648 B -40.59%
Simulation one 402.7 µs 590.3 µs -31.78%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information (16bf967) with main (bcd7e64)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (16bf967) during the generation of this report, so bcd7e64 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown

Greptile Summary

This PR wires up --perf-prof and optional V8 log flags for walltime profiling with samply, and fixes the instrument window placement in both the tinybench and vitest plugins by driving startBenchmark/stopBenchmark from tinybench's suite-level setup/teardown hooks rather than wrapping Task.run directly.

  • Core flags: getV8Flags gains a walltime case that emits --perf-prof (and log-file flags when CODSPEED_V8_LOG is set); linuxPerf.start/stop is skipped in walltime mode.
  • tinybench-plugin refactor: task fn/fnOpts are now captured in a WeakMap at bench.add time (fixing tinybench v6 private-field incompatibility); the root frame is baked in at registration rather than at run time; installInstrumentHooks replaces the old wrapWithInstrumentHooks wrappers to bracket only the measured loop.
  • vitest-plugin refactor: importTinybench now returns an InstrumentedBench subclass whose constructor installs per-bench hooks, and closeInstrumentWindow correctly emits markers before stopBenchmark to preserve the expected FIFO ordering.

Confidence Score: 5/5

The core logic changes are safe to merge; the marker-ordering issue in the tinybench walltime teardown was already identified in prior review rounds.

The V8 flag additions and linuxPerf gating are straightforward and low-risk. The tinybench-plugin refactor correctly replaces the broken private-field cast pattern with a WeakMap capture, and the vitest-plugin's closeInstrumentWindow already emits markers in the right order. The only unresolved finding in this pass is a missing Linear reference on a TODO comment in the workflow file.

packages/tinybench-plugin/src/walltime.ts — the marker-ordering issue (stopBenchmark before addMarker in the teardown hook) flagged in prior threads remains unaddressed in this diff.

Important Files Changed

Filename Overview
.github/workflows/codspeed.yml Adds samply profiler env var and pins an alpha runner version (v4.17.7-alpha.2) with a TODO that lacks a Linear issue reference
packages/tinybench-plugin/src/walltime.ts Major refactor: drives instrumentation window via bench setup/teardown hooks; marker ordering (stopBenchmark before addMarker) has been flagged in prior review threads
packages/vitest-plugin/src/walltime/index.ts Refactored to drive instrument window from per-bench setup/teardown hooks; closeInstrumentWindow correctly emits markers before stopBenchmark
packages/tinybench-plugin/src/analysis.ts Switches to captured task data map instead of casting private task fields; adds optimizeFunctionSync warm-up pass to the sync path; no markers sent in analysis mode
packages/core/src/introspection.ts Adds walltime case to getV8Flags switch: emits --perf-prof and optional V8 log-file flags when CODSPEED_V8_LOG is set; walltime case is missing break (flagged in prior thread)
packages/tinybench-plugin/src/benchOptions.ts New helper to abstract v5 (bench.opts) vs v6 (bench directly) options layout, enabling in-place mutation of setup/teardown hooks
packages/tinybench-plugin/src/taskData.ts New WeakMap-backed store capturing fn/fnOpts per task at bench.add time, replacing unsafe private-field casts that broke in tinybench v6
packages/tinybench-plugin/src/shared.ts Removes wrapWithInstrumentHooks/wrapWithInstrumentHooksAsync and sendBenchmarkMarkers from base class; adds getTaskData helper
packages/tinybench-plugin/src/index.ts Captures fn/fnOpts into taskDataMap at add time and wraps with wrapWithRootFrameSync in walltime mode to pre-bake the root frame before tinybench stores the function
.github/workflows/ci.yml Excludes with-tinybench-v5 and with-tinybench-v6 from Node 18 matrix runs since tinybench v5+ requires Node >=20

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant TB as tinybench
    participant WR as WalltimeBenchRunner
    participant IH as InstrumentHooks (FIFO)

    Note over TB,IH: installInstrumentHooks() wires setup/teardown

    TB->>WR: opts.setup(task, "run")
    WR->>IH: startBenchmark()
    WR->>WR: "runStart = currentTimestamp()"
    TB->>TB: measured loop (task fn x N)
    TB->>WR: opts.teardown(task, "run")
    WR->>WR: "runEnd = currentTimestamp()"
    WR->>IH: stopBenchmark()
    WR->>IH: setExecutedBenchmark(pid, uri)
    WR->>IH: addMarker(BENCHMARK_START, runStart)
    WR->>IH: addMarker(BENCHMARK_END, runEnd)

    Note over WR,IH: tinybench plugin - markers land after StopBenchmark
    Note over WR,IH: vitest plugin closeInstrumentWindow - markers before StopBenchmark
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant TB as tinybench
    participant WR as WalltimeBenchRunner
    participant IH as InstrumentHooks (FIFO)

    Note over TB,IH: installInstrumentHooks() wires setup/teardown

    TB->>WR: opts.setup(task, "run")
    WR->>IH: startBenchmark()
    WR->>WR: "runStart = currentTimestamp()"
    TB->>TB: measured loop (task fn x N)
    TB->>WR: opts.teardown(task, "run")
    WR->>WR: "runEnd = currentTimestamp()"
    WR->>IH: stopBenchmark()
    WR->>IH: setExecutedBenchmark(pid, uri)
    WR->>IH: addMarker(BENCHMARK_START, runStart)
    WR->>IH: addMarker(BENCHMARK_END, runEnd)

    Note over WR,IH: tinybench plugin - markers land after StopBenchmark
    Note over WR,IH: vitest plugin closeInstrumentWindow - markers before StopBenchmark
Loading

Reviews (10): Last reviewed commit: "feat: to fixup tinybench marker clean up" | Re-trigger Greptile

Comment thread packages/tinybench-plugin/src/walltime.ts Outdated
Comment thread packages/tinybench-plugin/src/walltime.ts
Comment thread packages/core/src/introspection.ts
Comment thread packages/tinybench-plugin/src/shared.ts Outdated
@GuillaumeLagrange GuillaumeLagrange changed the title Add necessary flags to dump optimized inlining info and fix marker placement in tinybench Add necessary flags to dump optimized inlining info and fix walltime marker placement Jun 22, 2026
GuillaumeLagrange and others added 2 commits June 22, 2026 11:05
…only

The runner wrapped the entire tinybench Task.run() in the instrumentation
window, folding the run-mode setup/teardown hooks and processRunResult (which
sorts the latency samples twice and computes the full statistics) into the
recorded sample. That framework overhead showed up in the walltime flamegraph.

Drive the window from each bench's run-mode setup/teardown hooks instead, so it
brackets only the measured loop. Warmup already runs as a separate Vitest call
and is now excluded, and the post-loop statistics computation falls outside the
window. User-provided hooks are preserved.

The tinybench module namespace is frozen, so the instrumented Bench is handed
back through a fresh module-shaped object that Vitest destructures from rather
than reassigning the export.

Closes COD-2925
Co-Authored-By: Claude <noreply@anthropic.com>
tinybench v6 moved the benchmark function, its options, and the resolved
bench options behind ES private fields (and flattened the options onto the
bench instance), which broke the plugin's reliance on reaching those
internals through casts: analysis mode crashed with "fn is not a function"
and walltime mode crashed reading `bench.opts.setup`.

Capture the function and options ourselves when `bench.add` runs, normalize
option access across the v4/v5 `bench.opts` layout and the v6 flattened one,
bake the walltime root frame into the registered function instead of mutating
the (now private) task function, and opt back into sample retention that v6
disabled by default. Add dedicated example fixtures pinning tinybench v5 and
v6 so CI exercises every supported major, excluding them from the Node 18 leg
since tinybench v5+ requires Node >=20.

Closes COD-2929
Co-Authored-By: Claude <noreply@anthropic.com>

Generated with AI Agent (Claude Code)
@GuillaumeLagrange GuillaumeLagrange force-pushed the cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information branch 2 times, most recently from 5b668b0 to 89b8a9a Compare June 22, 2026 09:21
Comment thread packages/tinybench-plugin/src/walltime.ts
@GuillaumeLagrange GuillaumeLagrange force-pushed the cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information branch from ad2afb2 to c52eabe Compare June 22, 2026 12:43
Comment thread packages/tinybench-plugin/src/analysis.ts Outdated
@GuillaumeLagrange GuillaumeLagrange force-pushed the cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information branch 2 times, most recently from ad2afb2 to f7030ac Compare June 22, 2026 13:53
@GuillaumeLagrange GuillaumeLagrange force-pushed the cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information branch from f7030ac to 16bf967 Compare June 22, 2026 13:57
@GuillaumeLagrange GuillaumeLagrange merged commit 16bf967 into main Jun 22, 2026
30 checks passed
@GuillaumeLagrange GuillaumeLagrange deleted the cod-2821-v8-maglevturbofan-inlining-loses-nested-inline-information branch June 22, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants