Skip to content

feat: bundle generated code cache into product - #336410

Merged
Robo (deepak1556) merged 1 commit into
mainfrom
robo/generate_code_cache_ci
Sep 26, 2026
Merged

Robo (deepak1556) merged 1 commit into
mainfrom
robo/generate_code_cache_ci

Conversation

@deepak1556

@deepak1556 Robo (deepak1556) commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Today main, extension host, shared process, pty host, and agent host repeatedly parses and compiles its startup modules. This change moves that work to build time. CI launches the packaged application once, generates a compile cache for each process, and bundles the caches with the product. At runtime, caches are consumed in portable, read-only mode, so application resources are never modified.

Depends on #336697

@deepak1556 Robo (deepak1556) added this to the 1.139.0 milestone Sep 16, 2026
@deepak1556 Robo (deepak1556) self-assigned this Sep 16, 2026
Copilot AI balanced review requested due to automatic review settings September 16, 2026 12:13

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.

Copilot review overview

🟡 Changes recommended

Four moderate findings remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite (auto)
Findings: 2 Medium severity

Note

Copilot is running an experiment and ran this review at Lite.

Open (2)
What changed in this PR

Adds build-time Node.js compile caches for VS Code startup processes, packaged for portable read-only runtime use.

Changes:

  • Enables caching across main, extension, shared, pty, and agent host processes.
  • Adds cache generation, validation, readiness coordination, and tests.
  • Updates bundling and universal macOS packaging.
File Reviewed change Findings
src/​vs/​workbench/​api/​node/​extHostExtensionService.ts Signals extension-host cache readiness. —
src/​vs/​workbench/​api/​common/​extHostExtensionService.ts Adds eager-extension lifecycle support. —
src/​vs/​platform/​terminal/​node/​ptyHostMain.ts Signals pty-host readiness. —
src/​vs/​platform/​agentHost/​node/​agentHostService.ts Exposes eager agent-host startup. —
src/​vs/​platform/​agentHost/​node/​agentHostMain.ts Signals agent-host readiness. —
src/​vs/​code/​electron-utility/​sharedProcess/​sharedProcessMain.ts Signals shared-process readiness. —
src/​vs/​code/​electron-main/​app.ts Coordinates startup and cache generation. —
src/​vs/​base/​node/​nodeCompileCache.ts Implements runtime cache handling and eager modules. Moderate (1 vote): nested production bundle paths can make eager module paths invalid.
src/​mainImpl.ts Contains deferred main-process startup logic. —
src/​main.ts Enables caching before startup loads. —
src/​bootstrap-fork.ts Enables caches for utility processes. —
eslint.config.js Updates imports and layering restrictions. —
build/​next/​index.ts Bundles the deferred main implementation. —
build/​lib/​test/​nodeCompileCache.test.ts Tests cache paths, targets, and validation. —
build/​lib/​nodeCompileCache.ts Generates and validates packaged caches. Moderate (2 votes): inherited internal environment overrides can redirect generation outside the packaged cache directory.
build/​gulpfile.vscode.ts Integrates cache generation into packaging. Moderate (1 vote): the legacy bundler can inline mainImpl, leaving its generated cache unused.
build/​darwin/​create-universal-app.ts Copies caches into universal macOS applications. Moderate (2 votes): copying only arm64 cache entries causes the x64 app to skip them.

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

Comment thread build/darwin/create-universal-app.ts Resolved
Comment thread build/lib/nodeCompileCache.ts Resolved
@deepak1556
Robo (deepak1556) force-pushed the robo/generate_code_cache_ci branch from 3748e93 to 29bbfa9 Compare September 18, 2026 04:57
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 90da9001 Current: de5f36e3

Changed (2)

chat/scrollAnchoring/chatScrollAnchoring/CompletedVisibleHeader/Dark
Before After
before after
chat/scrollAnchoring/chatScrollAnchoring/CompletedOffscreenHeader/Dark
Before After
before after

4 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

@deepak1556 Robo (deepak1556) modified the milestones: 1.139.0, 1.140.0 Sep 21, 2026
@deepak1556
Robo (deepak1556) force-pushed the robo/generate_code_cache_ci branch 5 times, most recently from 17e6355 to 6efd83a Compare September 25, 2026 19:29
@deepak1556

Copy link
Copy Markdown
Collaborator Author

Switching to full eager compilation based on the following metrics.

Screenshot 2026-09-26 at 21 54 00 Screenshot 2026-09-26 at 21 53 12

@deepak1556
Robo (deepak1556) force-pushed the robo/generate_code_cache_ci branch 2 times, most recently from 0ad2909 to e5d374e Compare September 26, 2026 13:02
@deepak1556
Robo (deepak1556) marked this pull request as ready for review September 26, 2026 13:04
@deepak1556
Robo (deepak1556) enabled auto-merge (squash) September 26, 2026 13:04
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/platform/terminal/node/ptyHostMain.ts

@deepak1556
Robo (deepak1556) marked this pull request as draft September 26, 2026 13:06
auto-merge was automatically disabled September 26, 2026 13:06

Pull request was converted to draft

@deepak1556
Robo (deepak1556) force-pushed the robo/generate_code_cache_ci branch from a0b6077 to 7479148 Compare September 26, 2026 13:25
@deepak1556
Robo (deepak1556) marked this pull request as ready for review September 26, 2026 13:28
@deepak1556
Robo (deepak1556) enabled auto-merge (squash) September 26, 2026 13:47
@deepak1556
Robo (deepak1556) merged commit fb6287c into main Sep 26, 2026
55 of 56 checks passed
@deepak1556
Robo (deepak1556) deleted the robo/generate_code_cache_ci branch September 26, 2026 18:21
@bryanchen-d

Copy link
Copy Markdown
Collaborator

Robo (@deepak1556) FYI: main CI 492985 failed once in Build client (macOS arm64) on cache validation:

Node.js compile cache generation produced unexpected shared-process cache entries in …/node-compile-cache/shared-process/v24.22.1-arm64-7034790f: e9b4ed39.1b40xd

e9b4ed39.1b40xd is Node's own atomic-write temp file (<entry>.XXXXXX from mkstemp, renamed once it's written). So the shared process was still writing its compile cache when validateNodeCompileCache read the directory. It hasn't failed in about 690 Build client steps since Oct 23, so it's rare. Here is the race as I read the code:

  • The shared process calls markNodeCompileCacheReady() (flushCompileCache(), then .ready) and keeps running. With eager: true, it keeps compiling.
  • When waitForNodeCompileCacheReady() resolves, main calls lifecycleMainService.quit(). SharedProcess.onWillShutdown only posts SharedProcessLifecycle.exit and drops the handle. It doesn't join the shutdown, so main can exit while the shared process is still tearing down.
  • Node writes the compile cache again when the process exits. runCacheGeneration resolves on the main process close event (utility process stdio is piped to main, not to the generator), and validation can then read the shared-process directory mid-write. If Electron kills the utility process mid-write instead, the temp file stays behind, and validation would still reject it.

Two possible fixes:

  1. In the product, only when VSCODE_GENERATE_NODE_COMPILE_CACHE=1: have main join onWillShutdown on the shared process's exit, using waitForExit with a bounded timeout, so nothing is still writing when main exits. The pty host and agent host may need the same.
  2. In the build: before validating, wait until no <8 hex>.<6 chars> temp entries remain in the cache directories, or until a bounded deadline. Then delete any orphan that's left, since the target entry either already exists from the earlier flush or was never renamed.

I'm happy to send a draft for either one. Which would you prefer?

Co-authored with Copilot

@bryanchen-d

Copy link
Copy Markdown
Collaborator

Adding recurrence evidence: across 7,838 Build client steps since Oct 23 this has hit 4 times, and each time it was shared-process with a <hash8>.<rand6> temp entry:

  • 488834 (5f659e45.uz8uI2, Windows)
  • 489047 (9f86d8f7.WhKxqm, Windows)
  • 492116 (manual, Windows)
  • 492985 (macOS arm64)

So it isn't specific to one platform, and the rate is low. No official build has failed on it yet.

Co-authored with Copilot

@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants