Skip to content

startup: add tracing improvements and fix help fast path#67

Open
sonukapoor wants to merge 2 commits intowasmerio:mainfrom
sonukapoor:startup-investigation
Open

startup: add tracing improvements and fix help fast path#67
sonukapoor wants to merge 2 commits intowasmerio:mainfrom
sonukapoor:startup-investigation

Conversation

@sonukapoor
Copy link
Copy Markdown
Contributor

@sonukapoor sonukapoor commented Apr 13, 2026

Summary

This PR improves startup observability, documents the cold-start investigation, keeps a small CLI startup optimization, and adds a native --help fast path that fixes broken non-interactive help output and makes --help about 7.7x faster.

It adds finer-grained host-side startup tracing before JS bootstrap, including:

  • OpenSSL configuration loading
  • OpenSSL CSPRNG validation
  • N-API environment creation
  • runtime attachment sub-steps

It also includes a low-risk CLI startup optimization that avoids unnecessary cwd resolution when neither --env-file* nor --experimental-config-file* is present.

Why

The existing startup trace was useful for JS/bootstrap attribution, but it was still too coarse on the host side.

This PR makes it easier to answer where startup time is going before first useful JS executes, especially around:

  • OpenSSL startup
  • N-API environment creation
  • runtime attachment and hook installation

It also adds a startup investigation document so future optimization work can build on measured findings rather than repeated guesswork.

What changed

Startup tracing

Added or expanded host-side trace phases such as:

  • cli.env.openssl.configure.begin
  • cli.env.openssl.configure.end
  • cli.env.openssl.csprng-check.begin
  • cli.env.openssl.csprng-check.end
  • cli.env.create-napi-env
  • cli.env.attach-runtime.environment
  • cli.env.attach-runtime.process-exit-handler
  • cli.env.attach-runtime.cleanup-stages

CLI startup optimization

Improved effective CLI-state handling so simple startup paths do not resolve cwd unnecessarily when env/config-file features are not in use.

Documentation

Added docs/startup-investigation.md, covering:

  • current startup path
  • measured hotspots
  • host-side follow-up findings
  • ranked next opportunities
  • architectural comparison points from other runtimes

Findings

Current findings from the investigation:

  • edge --version already avoids OpenSSL and N-API environment creation
  • edge --help does not appear to semantically require OpenSSL, but still goes through runtime/bootstrap in the current implementation
  • edge -e "" still genuinely requires runtime/bootstrap and N-API environment creation
  • blanket OpenSSL deferral for trivial eval is not obviously safe because current startup preserves fail-fast config/provider/CSPRNG behavior

Measurement

Using repeated hyperfine runs against a saved baseline binary:

  • edge -e ""

    • before: 41.6 ms ± 1.3
    • after: 40.9 ms ± 1.0
    • result: about 1.7% improvement
  • edge benchmarks/workloads/empty-startup.js

    • before: 40.4 ms ± 1.2
    • after: 40.2 ms ± 0.8
    • result: small but favorable improvement

The host-side follow-up tracing improved attribution further, but did not produce an additional measurable speedup on its own.

What this PR does not do

  • no snapshot pipeline yet
  • no broad bootstrap refactor
  • no claim of a large cold-start improvement
  • no retained special-case fast path for --help

Verification

cmake --build build-edge -j8
./build-edge/edge --version
./build-edge/edge --help >/dev/null
./build-edge/edge -e ''
EDGE_STARTUP_TRACE=1 ./build-edge/edge --version
EDGE_STARTUP_TRACE=1 ./build-edge/edge --help
EDGE_STARTUP_TRACE=1 ./build-edge/edge -e ''

@sonukapoor sonukapoor force-pushed the startup-investigation branch from b2b9f1f to 75abb89 Compare April 13, 2026 03:06
@sonukapoor sonukapoor changed the title startup: add tracing improvements and initial cold-start investigation startup: add tracing improvements and fix help fast path Apr 14, 2026
@sonukapoor
Copy link
Copy Markdown
Contributor Author

@syrusakbary Please take a look

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