Skip to content

Persist state between profiled startup runs - #331860

Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
mainfrom
dev/dmitriv/persist-profiled-startup-state
Aug 20, 2026
Merged

Persist state between profiled startup runs#331860
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
mainfrom
dev/dmitriv/persist-profiled-startup-state

Conversation

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Problem

Desktop startup profiling writes its timing output and then calls nativeHostService.exit(0). This intentionally avoids waiting for a complete application shutdown, but it also bypasses the normal shutdown storage flush.

That makes repeated profiler runs less representative of a normal clean warm start. State normally persisted during shutdown is absent from the next run.

One confirmed example is the editor font measurement cache:

  • Current profiler behavior: no editorFontInfo entry after the run
  • With this change: editorFontInfo is persisted after the warmup

Without the persisted entry, the next profiler run repeats synchronous DOM character-width measurement instead of restoring the cached font metrics. CPU traces confirmed that DomCharWidthReader._readFromDomElements is present in every current profiler run and absent after a persisted warmup.

This is a performance-infrastructure accuracy issue. Normal VS Code shutdown already flushes the same state; this does not change normal user startup or shutdown behavior.

Change

After startup timers, duration markers, heap statistics, and output files have been completed:

  1. Flush the workbench storage service with WillSaveStateReason.SHUTDOWN.
  2. Wait up to five seconds for persistence.
  3. Preserve the existing hard process exit in a nested finally.
  4. Exit nonzero if the flush rejects or times out.

The flush happens after all measured values are collected and written, so storage persistence is not included in the reported startup interval. It only extends the unmeasured process lifetime after results are available.

Measurement accuracy

This makes repeated profiler runs use the same persisted state that follows a normal clean VS Code shutdown.

Verified behavior:

State/behavior Current profiler With change
editorFontInfo after warmup Missing Persisted
Next-run DOM font measurement Repeated Restored from cache
Flush failure/timeout Not applicable Logged and reported through nonzero exit

The nonzero exit is important: if persistence fails, the performance harness must reject the run rather than silently accepting a following run with unexpectedly cold state.

The flush also emits the standard shutdown save event, so other components participating in normal shutdown persistence can provide representative warm state to subsequent measurements.

Scope / lack of product behavior changes

  • The new code only runs when startup profiling output or duration markers were requested.
  • Regular VS Code windows return before entering this profiling path.
  • Normal product startup remains unchanged.
  • Normal product shutdown remains unchanged.
  • Reported timer and marker values are captured before the flush.
  • Existing hard-exit behavior remains, including on flush failure.

Validation

  • npm run typecheck-client
  • npm run transpile-client
  • Repeated source profiler runs completed successfully.
  • Repeated fully bundled profiler runs completed successfully.
  • SQLite inspection verified editorFontInfo is persisted only with the fix.
  • Warmed CPU inspection verified the unwanted font DOM measurement is absent after persistence.
  • Flush timeout is bounded to five seconds.
  • Flush rejection/timeout exits nonzero so the harness cannot accept inaccurate warm-state measurements.
  • Independent implementation and final diff reviews found no significant correctness issue.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 20, 2026 18:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Persists representative warm-start state after desktop startup profiling without affecting measured timings.

Changes:

  • Flushes workbench storage with shutdown semantics.
  • Bounds persistence to five seconds and exits nonzero on failure.
  • Preserves the profiler’s hard-exit behavior.
Show a summary per file
File Description
src/vs/workbench/contrib/performance/electron-browser/startupTimings.ts Flushes profiled startup state before exiting.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as ready for review August 20, 2026 20:25
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 310ba23 into main Aug 20, 2026
45 of 46 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the dev/dmitriv/persist-profiled-startup-state branch August 20, 2026 21:05
@vs-code-engineering vs-code-engineering Bot added this to the 1.135.0 milestone Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants