Skip to content

Kill and restart esbuild instances during watch mode#321219

Merged
mjbvz merged 2 commits into
microsoft:mainfrom
mjbvz:dev/mjbvz/direct-skink
Jun 16, 2026
Merged

Kill and restart esbuild instances during watch mode#321219
mjbvz merged 2 commits into
microsoft:mainfrom
mjbvz:dev/mjbvz/direct-skink

Conversation

@mjbvz

@mjbvz mjbvz commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Reduces memory usage since we don't need rebuilds all that often. Perf still is reasonable in for the full rebuild

Reduces memory usage since we don't need rebuilds all that often. Perf still is reasonable in for the full rebuild
Copilot AI review requested due to automatic review settings June 12, 2026 21:23

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

This PR changes the shared extension esbuild watch runner to avoid retaining an esbuild build context during watch mode, instead performing a full esbuild.build() per file-change and stopping the esbuild service after builds to reduce memory usage.

Changes:

  • Replace persistent esbuild.context(...).rebuild() usage with full esbuild.build(...) per watch-triggered rebuild.
  • Call esbuild.stop() after non-watch builds (and after each watch-triggered build) to release the esbuild service/resources.
Show a summary per file
File Description
extensions/esbuild-common.mts Switch watch-mode rebuild strategy to full builds per change and stop esbuild services after builds to reduce memory use.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
Comment on lines 56 to 74
let debounce: ReturnType<typeof setTimeout> | undefined;
const rebuild = () => {
if (debounce) {
clearTimeout(debounce);
}
debounce = setTimeout(async () => {
try {
await ctx.cancel();
const result = await ctx.rebuild();
// Also instead of retaining the esbuild context, we are re-running the entire build on each change.
// This reduces memory usage since most projects don't need to be re-built often.
const result = await esbuild.build(options);
if (result.errors.length === 0) {
await didBuild?.();
}
} catch (error) {
console.error('[watch] build error:', error);
} finally {
esbuild.stop();
}
}, 100);

@juttadnanzafar-hue juttadnanzafar-hue left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

jutt

alexdima
alexdima previously approved these changes Jun 12, 2026
@mjbvz mjbvz merged commit ed86c90 into microsoft:main Jun 16, 2026
39 of 40 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.126.0 milestone Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants