Skip to content

diagnostics: add startup phase trace for runtime bootstrap#66

Open
sonukapoor wants to merge 3 commits into
wasmerio:mainfrom
sonukapoor:bugfix/cold-start-first-pass
Open

diagnostics: add startup phase trace for runtime bootstrap#66
sonukapoor wants to merge 3 commits into
wasmerio: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.

@sonukapoor sonukapoor force-pushed the bugfix/cold-start-first-pass branch from 6d8019d to 759a519 Compare May 4, 2026 17:26
Comment thread src/edge_runtime.cc Outdated
}
return 1;
}
startup_trace.Mark("install-module-loader");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be compiled-in if tracing is disabled

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d397007. Runtime startup tracing now follows the existing CLI pattern: the tracer implementation and mark calls are behind ENABLE_TRACING, and the normal build no longer contains the startup trace marker strings. Verified both normal and tracing builds locally.

Copy link
Copy Markdown
Member

@syrusakbary syrusakbary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address comments

@sonukapoor sonukapoor requested a review from syrusakbary May 11, 2026 01:52
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