demo · v136

Critical bundle annotator

The intended workflow: paste a bundle, the tool detects which exports are called during module evaluation, and inserts the //# allFunctionsCalledOnLoad magic comment on top of the modules whose code runs in the critical path. The sibling concept benchmarks; this concept is the build-time annotator that decides where to put the hint.

Paste source. Click "annotate" to add the magic comment header if eager-compilation pays off.
functions defined
0
functions called on load
0
hint emitted?

annotated source

the code

// Heuristic: if > 60% of declared functions are called during top-level
// module evaluation, emit the file-wide hint.
const declared = countFunctionDeclarations(src);
const called   = collectCalledIdentifiers(src);
const ratio    = called.size / declared.length;
if (ratio > 0.6) return "//# allFunctionsCalledOnLoad\n" + src;

why this angle

The sibling concept asks "does the hint speed up loading?" by timing a synthetic blob. This concept answers "when do I put the hint?" by running the upstream decision: parse the source, find function declarations, check which ones are invoked during top-level evaluation, and emit the hint if the ratio is high enough. This is the build-tool angle — webpack/Rollup/esbuild plugins are expected to do exactly this transform.

see also