feat(coding-agent): reduce bundled startup work

This commit is contained in:
Armin Ronacher 2026-08-23 00:02:45 +02:00
parent 62bcbf6be0
commit faecac2ca8
3 changed files with 20 additions and 18 deletions

View file

@ -8,6 +8,7 @@
### Changed
- Changed the bundled Node.js runtime to load jiti's Babel transform only when an extension needs it, reducing CLI startup time and bundle size.
- Changed syntax highlighting to initialize only twenty common languages eagerly and defer the remaining grammars until after the initial TUI render, reducing CLI startup time.
- Changed the Node.js CLI and RPC entrypoints to load a bundled runtime, reducing startup filesystem reads while keeping the public library and legacy module paths on the modular runtime for normal dependency identity.
- Changed session sharing to render clickable terminal links and Radius shares to display only the artifact's canonical URL.

View file

@ -1,4 +1,3 @@
import { createRequire } from "node:module";
import hljs from "highlight.js/lib/core.js";
import bash from "highlight.js/lib/languages/bash.js";
import c from "highlight.js/lib/languages/c.js";
@ -22,11 +21,6 @@ import swift from "highlight.js/lib/languages/swift.js";
import typescript from "highlight.js/lib/languages/typescript.js";
import { decodeHtmlEntityAt } from "./html.ts";
const moduleRequire = createRequire(import.meta.url);
declare const PI_BUNDLED_NODE: boolean;
declare const Bun: unknown;
declare const require: (specifier: string) => unknown;
const eagerLanguages = {
python,
java,
@ -60,18 +54,13 @@ export function loadAllHighlightLanguages(): Promise<void> {
if (!allLanguagesPromise) {
allLanguagesPromise = new Promise((resolve) => {
setImmediate(() => {
try {
// Static require lets esbuild and Bun include this deferred module in
// standalone bundles. Source and unbundled Node runtimes need createRequire.
if ((typeof PI_BUNDLED_NODE !== "undefined" && PI_BUNDLED_NODE) || typeof Bun !== "undefined") {
require("highlight.js/lib/index.js");
} else {
moduleRequire("highlight.js/lib/index.js");
}
} catch {
// Eager languages and plaintext fallback remain available.
}
resolve();
void import("highlight.js/lib/index.js").then(
() => resolve(),
() => {
// Eager languages and plaintext fallback remain available.
resolve();
},
);
});
});
}

View file

@ -17,6 +17,7 @@ const banner = {
};
const allowedExternalPackages = new Set([
"@silvia-odwyer/photon-node",
"jiti",
// Optional native accelerators. Their callers fall back to JavaScript when absent.
"bufferutil",
"utf-8-validate",
@ -24,6 +25,13 @@ const allowedExternalPackages = new Set([
"supports-color",
]);
const lazyJitiPlugin = {
name: "lazy-jiti-transform",
setup(build) {
build.onResolve({ filter: /^jiti\/static$/ }, () => ({ external: true, path: "jiti" }));
},
};
function commonBuildOptions() {
return {
absWorkingDir: repoRoot,
@ -38,6 +46,10 @@ function commonBuildOptions() {
minifySyntax: true,
minifyWhitespace: true,
platform: "node",
// The source uses jiti/static so Bun embeds its Babel transform. The Node
// package can use regular jiti from its direct dependency and load Babel
// only when an extension actually needs transformation.
plugins: [lazyJitiPlugin],
sourcemap: false,
target: "node22.19",
// Do not apply the monorepo's source-oriented path aliases while bundling