Skip to content

Main-process, host and preload bundles as Latin-1 text (about 6 MB off mawsd and the engine host) - #369

Merged
SSFSKIM merged 1 commit into
masterfrom
build/ascii-main-bundles
Oct 30, 2026
Merged

SSFSKIM merged 1 commit into
masterfrom
build/ascii-main-bundles

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Every main-process, host and preload bundle is now emitted with no character above U+00FF. Node keeps each loaded file's source in the V8 heap. If a file holds even one character above U+00FF (a curly quote in a log line, a dash in a comment), V8 stores the whole file at two bytes per character. On master, 34 emitted files are like that. They include main's index.js (6.15 M characters), the engine host (4.47 M), the pty host (0.56 M), mawsd.js, both preloads, and 28 chunks (mostly shiki grammars, plus the identity, identity-file and host-supervisor chunks). After this change, each is held at one byte per character.

This lands before O3-D's M7 measured series so that the series measures it.

The change

scripts/latin1-bundles.ts is a Rollup output plugin. electron.vite.config.ts wires it into main's output and the preloads' output.

  • The re-print. A chunk that holds a character above U+00FF is re-printed through esbuild's transform with charset: 'ascii'. esbuild escapes such characters wherever an escape means the same thing: strings, untagged templates, identifiers and property names. A chunk already within Latin-1 is returned as it is.
  • What esbuild leaves verbatim. acorn parses the re-print to find where each leftover character sits, and each place is handled differently:
    • Comments: the character is written as \uXXXX text, which is inert there.
    • Regular expression literals: the character is written as \uXXXX, which matches the same code unit. An identity escape (\—, Annex B) folds into the escape.
    • Tagged templates (String.raw included): the build fails, because an escape would change the raw text.
    • Anywhere else: the build fails as well.
  • The ?modulePath hosts. The host builds take main's output options (electron-vite's bundleEntryFile merges main's config), so the engine and pty hosts are re-printed in their own builds. They reach main's bundle as assets.
  • Guards:
    • In the plugin: generateBundle fails the build if any emitted .js file, chunk or asset, still holds a character above U+00FF. renderStart refuses sourcemap, since the re-print does not chain maps.
    • In the unit gate: src/engine-host/bundle-guard.test.ts gains a case that reads every built out/main/**/*.js and out/preload/*.js file. It catches a config change that drops the plugin, a case where the build itself would still pass.
    • The transform's own suite: test/latin1-bundles.test.ts runs each transformed program in a VM and compares values with the original. It covers strings, identifiers, comments, and regexes with identity escapes, astral characters, u/v flags and named groups. It also checks the tagged-template refusal and the plugin's hooks.
  • New dependency. acorn 8.18.0 becomes a direct devDependency; it was already in the lockfile.
  • Build time. The main build takes about 1 to 4 s longer.

Behaviour

  • Same program. Builds from master and from this head were parsed with acorn and their ASTs compared (~/.local/share/maws-ascii/ast-equal.mjs). The comparison ignores positions, raw spellings, chunk hashes and the build-time stamp. It reads regex patterns with the introduced \uXXXX decoded. It compares tagged templates' raw text exactly.
    • Main: 249 files are byte-identical and 63 are re-printed with the same AST; 0 differ.
    • Preloads: 2 re-printed with the same AST.
    • On O3-D's tip (cf3114da9) with this commit added: 248 byte-identical, 67 same AST, 0 differ.
  • Source maps. None are produced or consumed. electron-vite's main and preload presets leave build.sourcemap at Vite's false. No script passes --sourcemap. No .map file is emitted. Nothing under src/, scripts/ or electron-builder.yml reads one: there is no --enable-source-maps, setSourceMapsEnabled, source-map-support or prepareStackTrace. Turning maps on now fails the build with a message, rather than shipping maps that are silently wrong.
  • Raw template text. Master's main bundles hold 107 tagged templates, the preloads 2. None has raw text above U+007F. esbuild prints tagged raw text verbatim, and the rewrite never touches it. The AST comparison above checks tagged raw text exactly. A future tagged template above U+00FF fails the build, naming the place.
  • The leftover rewrite. It runs only inside the comment and regexp ranges acorn reports. Anything else throws.
    • Master has 14 regex literals above U+00FF: NUMBERED, WORD, WIDE, MARKDOWN_LINK_INPUT_REGEX, MARKDOWN_LINK_PASTE_REGEX, xmlAttr, unicodeSubRegEx, a tiptap find: rule and a control-character strip.
    • None of them has an identity escape.
    • Each is used only through exec, test, match, matchAll or replace; none has its .source read.
  • Code that ships its own source.
    • src/main/presentations/export.ts sends String(measureDeckPage) and String(shrinkScale) through executeJavaScript. Both functions' text is byte-identical in the two builds.
    • The engine host's search worker (src/engine-host/fs/search-text.ts) is built from a String.raw template that interpolates isMadeUpFinalAnswer. The 66-line template and the function's text are both byte-identical.
    • STAGE(...) is an untagged template, and its cooked value is unchanged.
    • No other executeJavaScript, new Worker(…, { eval: true }), new Function or vm source-shipping site exists in main-process code.

The target, checked directly

None of these files holds a character above U+00FF:

  • pnpm build:main-preload: 312 main files and 2 preloads.
  • electron-vite dev's build: 314 files. This is main and the preloads built through resolveConfig(…, 'serve', 'development'), the way createServer builds them, without starting Electron.
  • The packaged app. build:helper, then electron-vite build, then electron-builder --mac dir. In MAWS.app/Contents/Resources/app.asar, out/main (312 files) is identical to the build, and out/preload has 2 files. The renderer is out of scope and still holds 69 such files.

Memory

Method: the O3-D executor's. Each run reads V8 heap used after a forced GC (--expose-gc, stats.cjs on SIGUSR2). Master and head runs alternate on the MacBook, three runs each. Runs varied by under 12 KB.

process scene before after change
engine host idle, detached as mawsd spawns it 44,097,424 39,656,656 −4.24 MiB
mawsd cold (master has no spine in mawsd) 21,390,632 20,652,872 −0.70 MiB
mawsd released, 5k-session fixture: O3-D tip cf3114da9 vs the same tree with this commit 26,490,512 24,861,976 −1.55 MiB
engine host idle, O3-D tip vs with this commit 44,270,228 39,832,072 −4.23 MiB

Notes on the table:

  • Before and after are medians, in bytes.
  • Engine host. mawsd's spawn drops NODE_OPTIONS, so the engine host is started directly with the same arguments.
  • Combined. The released mawsd and the engine host together come to about 6.1 MB, against the idle footprint bound's reading of 96,755 KiB.
  • Not measured. Main's own heap should drop by about 6 MB too (index.js is 6.15 M characters), but Electron is not launched on this Mac, so that is not measured.

Not done

  • Externals. The hosts load zod and the MCP SDK from node_modules, and some of their files hold characters above U+00FF. In the asar, the affected zod files total 1.8 M characters and the SDK's 0.65 M, but only part of that is loaded. Rewriting node_modules at packaging time is a separate change.
  • Source-map chaining. Not implemented, since nothing produces or consumes maps; the guard says so if that changes.

Gate

All runs are on head b77354d50 (tree bc155c253).

  • Run 41018437812, --gates all --class1a pool --runner macos. I cancelled it at 07:28Z to keep the Mac mini free for O3-D's booking. By then 40 jobs were green, no job had failed, and no flaky annotations had been recorded.
    • Green: class 1a (static, unit 1–4, probes), unit:darwin, both e2e builds, and every e2e group except the 13 below. That includes default, discover, connectors-oauth and browser-comment, which ran on the mini.
  • Run 41020368991, --lane hosted. It covered packaged and the 13 groups the cancel stopped: library, agents, design, c7-utility, terminal, delivery, browser, presentations, design-systems, panel, browser-import, lane-a and connectors-direct. All green, with no flaky annotations.
    • packaged: e2e:packaged 213 passed and 239 skipped; supervisor packaged, daemon packaged and voice packaged each passed. No flaky: line in the job log.
  • Run 41037672797, --gates all --class1a pool --runner macos, launched at 10:01Z after the mini booking. Green on the first attempt: 51 jobs, 41 of them e2e groups, plus class 1a, unit:darwin and both e2e builds. No flaky annotations. packaged is not part of all; its green run is 41020368991 above, on the same tree.

An independent review (doperpowers:reviewer-medium) of origin/master..b77354d50 had no material findings. It also checked the hash placeholders, acorn's script/module fallback and UTF-16 positions, and the electron-vite dev build, and ran the built presentation-measurement functions and search worker directly.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)

…1-bundles.ts) re-prints each main, host and preload chunk holding a character above U+00FF through esbuild's charset=ascii, writes what esbuild leaves in comments and regular expression literals (located by acorn) as \uXXXX, fails the build on any other leftover (a tagged template's raw text) and on any emitted .js file above U+00FF; V8 then holds each file's source at a byte a character (the engine host's 4.5 M characters, main's 6.2 M)

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
@SSFSKIM
SSFSKIM merged commit 67f4baf into master Oct 30, 2026
SSFSKIM added a commit that referenced this pull request Oct 30, 2026
…les)

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Oct 30, 2026
…tin-1 text (#369), about 6 MB off the daemon shape's idle footprint; tracker rows for the renderer's bundles and the hosts' node_modules

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
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