Skip to content

diagnostics: add startup phase trace for runtime bootstrap#66

Open
sonukapoor wants to merge 1 commit intowasmerio:mainfrom
sonukapoor:bugfix/cold-start-first-pass
Open

diagnostics: add startup phase trace for runtime bootstrap#66
sonukapoor wants to merge 1 commit intowasmerio:mainfrom
sonukapoor:bugfix/cold-start-first-pass

Conversation

@sonukapoor
Copy link
Copy Markdown
Contributor

Summary

Add an opt-in startup phase trace for runtime bootstrap diagnosis.

This PR adds lightweight, environment-gated tracing in src/edge_runtime.cc to emit per-phase startup timing markers during RunScriptWithGlobals.

  • env var: EDGE_STARTUP_TRACE=1
  • output channel: stderr
  • output shape: JSON-like one-line entries with:
    • edge_startup_trace (phase name)
    • delta_ms (time since previous marker)
    • total_ms (time since traced startup begin)

Why

Current benchmark work shows startup-sensitive gaps, but wall-clock totals alone do not identify which bootstrap phase dominates.

This trace is intended as a diagnosis artifact so follow-up performance changes can target concrete hotspots and produce before/after evidence per phase.

Scope

  • Diagnostics only.
  • No behavior or compatibility changes when EDGE_STARTUP_TRACE is unset.
  • No benchmark workload changes in this PR.

Example usage

EDGE_STARTUP_TRACE=1 ./build-edge/edge benchmarks/workloads/empty-startup.js
EDGE_STARTUP_TRACE=1 ./build-edge/edge -e ""

Example output (local)

{"edge_startup_trace":"install-process-object","delta_ms":2.51975,"total_ms":2.81742}
{"edge_startup_trace":"bootstrap.per_context.primordials","delta_ms":9.84379,"total_ms":12.7747}
{"edge_startup_trace":"bootstrap.realm","delta_ms":4.55288,"total_ms":17.7587}
{"edge_startup_trace":"bootstrap.node-and-web","delta_ms":16.6824,"total_ms":34.4411}

This local sample suggests bootstrap.node-and-web is a major hotspot candidate for the next narrow cold-start optimization pass.

@sonukapoor
Copy link
Copy Markdown
Contributor Author

Quick cold-start update:

Using EDGE_STARTUP_TRACE, I tested a few narrow startup optimizations with A/B runs against the same baseline binary.

Tried:

  • lazy-load in internal/bootstrap/switches/is_main_thread.js
  • lazy wiring in internal/bootstrap/node.js (source-map/builtin-module helper path)

Outcome:

  • no stable speedup yet
  • one attempt was noise-level
  • one regressed by ~1% on repeated runs
  • both were reverted

Current status: diagnostics improved, but no confirmed startup win yet.

Next: split bootstrap.node into finer sub-phases, then target the heaviest sub-phase with a narrow follow-up and report only if the gain is repeatable.

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.

1 participant