Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
55c658a
compile.ts: put misplaced doc comments on their declarations
claude Dec 6, 2026
1390a5c
compiler: move the helpers after the Compiler class into modules
claude Dec 6, 2026
3dbdecd
Merge remote-tracking branch 'origin/main' into ccr-eba7a8ac-oel4v3
claude Dec 6, 2026
085799d
compiler: move the compile contract's types into types.ts
claude Dec 6, 2026
37a00e2
compiler: move the passes of a compile into passes.ts
claude Dec 6, 2026
76feffe
bench, docs: follow the compiler's moved modules
claude Dec 6, 2026
14afee0
compiler: rename two locals that would shadow functions the class spl…
claude Dec 6, 2026
0ee6662
compiler: the class's positions and diagnostics as functions (positio…
claude Dec 6, 2026
b7896b5
compiler: the class's component-files methods as functions (component…
claude Dec 6, 2026
fd78132
compiler: the class's expand methods as functions (expand.ts)
claude Dec 6, 2026
01893b3
compiler: the class's instances methods as functions (instances.ts)
claude Dec 6, 2026
2b9d44c
compiler: the class's walk methods as functions (walk.ts)
claude Dec 6, 2026
cfdf30d
compiler: the class's bindings methods as functions (bindings.ts)
claude Dec 6, 2026
4d55426
compiler: the class's declarations methods as functions (declarations…
claude Dec 6, 2026
b2212b6
compiler: the class's prerender methods as functions (prerender.ts)
claude Dec 6, 2026
6bb43f1
compiler: the class's second-pass methods as functions (second-pass.ts)
claude Dec 6, 2026
250a9e2
compiler: the class's finish methods as functions (finish.ts)
claude Dec 6, 2026
7305752
compiler: setters for FW_COUNTING, FW_WALKING and APPLIED
claude Dec 6, 2026
64d90f5
compiler: the class's from-walk methods as functions (from-walk.ts)
claude Dec 6, 2026
183ca05
compiler: the class's aliases methods as functions (aliases.ts)
claude Dec 6, 2026
19b9e4c
compiler: the class's early-parts methods as functions (early-parts.ts)
claude Dec 6, 2026
c6c9e66
compiler: the class's space methods as functions (space.ts)
claude Dec 6, 2026
a6729b8
bench: time the compiler's phases in their stage modules
claude Dec 6, 2026
7cf941c
docs: name the modules that hold startsFalse, helperCalls and pageSpec
claude Dec 6, 2026
9d42d45
test: read the features the compiler adds from every compiler module
claude Dec 6, 2026
c1a6043
compiler: type the compiler the linker and units take
claude Dec 6, 2026
28a8697
compiler: keep B1's walk state in from-walk.ts, without setters
claude Dec 6, 2026
2fa7a76
compiler: drop the unused notUnrolled field
claude Dec 6, 2026
204f4f9
compiler: rename a shared template's props by syntax, not by text
claude Dec 6, 2026
921a7fd
Merge remote-tracking branch 'origin/main' into ccr-eba7a8ac-oel4v3
claude Dec 6, 2026
3f4415f
Merge remote-tracking branch 'origin/main' into ccr-eba7a8ac-oel4v3
claude Dec 6, 2026
8c085d4
changelog: a shared template's strings are no longer renamed
claude Dec 6, 2026
3599f4c
compiler: read other modules' state through functions, not imported lets
claude Dec 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ How to write an entry (from 0.21.0 on; older sections keep their own form):
- A swap that loads its page instead (the page answered an error, a module failed to load) still morphs its
`data-sn-transition` pair: the load is handed the link that started it
([page transitions](docs/navigation.md#page-transitions)).
- A production build no longer prints `$pp` in place of a string that spells a component's internal props name
(`'$p2'`) inside a template several components write alike: the build renames the props in the code it shares
between them, and now leaves strings alone.

## 0.23.1 (2026-12-02)

Expand Down
2 changes: 1 addition & 1 deletion bench/runtime/page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Mounts a page for the runtime benchmarks: the real compiler, a production build (no dev
// feature, no freezing), the document's own environment. Like `render()` from the testing
// module, minus its fake clock and dev checks, which would distort the timings.
import { compileParts } from '../../src/compiler/compile.js';
import { compileParts } from '../../src/compiler/passes.js';
import { compactIR } from '../../src/ir.js';
import { mount, type App } from '../../src/runtime/app.js';
import { $k } from '../../src/runtime/security.js';
Expand Down
7 changes: 4 additions & 3 deletions bench/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Plain Node scripts; nothing here is imported by sinter. A base checkout beside t
commit, `npm run build` there) is what the A/B and byte comparisons run against.

- `instr.mjs` + `hooks.mjs`: a preload. `node --import bench/tools/instr.mjs bench/astro/run-sinter.mjs <app>` wraps
`Compiler.prototype` methods (`SN_METHODS`, default `decideFor,settle,prerender,worklist,fileConstants,writtenState`;
`#1`/`#2` by pass) and `compile()` through a load hook, and prints each one's calls, sum, p25 and median at exit
the compiler's phases (`SN_METHODS`, default `decideFor,settle,prerender,worklist,fileConstants,writtenState`: a
`Compiler` method, or a stage module's exported function, which the load hook rebinds; `#1`/`#2` by pass) and
`compile()`, and prints each one's calls, sum, p25 and median at exit
(`SN_PHASES=<file>`: JSON lines instead). Wall clock (`SN_CLOCK=cpu`: thread CPU, which ticks at 4 ms on some
kernels). `SN_COUNT=1` also rewrites a few lines of `dist/compiler/compile.js` to count calls (row bindings run, proxy
kernels). `SN_COUNT=1` also rewrites a few lines of `dist/compiler/prerender.js` (and `first-paint.js`) to count calls (row bindings run, proxy
reads, rows walked, templates rendered, `writeFirstPaint` by kind…); a rewrite whose text is gone throws, so update it
with the code.
- `ab.mjs <rounds> <appA> <appB> [phases…]`: interleaved builds of two apps (each built by the checkout it links),
Expand Down
33 changes: 20 additions & 13 deletions bench/tools/hooks.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
// a load hook: appends instrumentation to the compiler's modules; SN_COUNT=1 also counts calls inside the evaluation
// a load hook: appends instrumentation to the compiler's modules (dist/compiler/*.js); SN_COUNT=1 also counts calls inside the evaluation
import { readFileSync } from 'node:fs';
const C = process.env.SN_COUNT === '1';
/** the counters, shared by every module a rewrite counts in */
const COUNT = 'const __c = (globalThis.__snCount ??= {});\nconst __n = (k, d = 1) => { __c[k] = (__c[k] ?? 0) + d; };\n';
/** must match instr.mjs */
const METHODS = (process.env.SN_METHODS ?? 'decideFor,settle,prerender,worklist,fileConstants,writtenState').split(',');
const rep = (src, a, b) => { if (!src.includes(a)) throw new Error('hook: not found ' + a); return src.replace(a, b); };
export async function load(url, ctx, next) {
const r = await next(url, ctx);
if (url.endsWith('/dist/compiler/compile.js')) {
let src = String(r.source ?? readFileSync(new URL(url)));
const file = url.match(/\/dist\/compiler\/([\w-]+\.js)$/)?.[1];
if (!file) return r;
const src0 = String(r.source ?? readFileSync(new URL(url)));
let src = src0;
const tail = [];
// the compiler's phases that are module functions now: rebind each one to its timed wrapper (instr.mjs)
for (const m of METHODS) if (src.includes(`export function ${m}(`)) tail.push(`${m} = globalThis.__snWrap ? globalThis.__snWrap(${JSON.stringify(m)}, ${m}) : ${m};`);
if (file === 'prerender.js') {
tail.push('globalThis.__snCollecting = collecting;');
if (C) {
src = 'const __c = (globalThis.__snCount ??= {});\nconst __n = (k, d = 1) => { __c[k] = (__c[k] ?? 0) + d; };\n' + src;
src = COUNT + src;
src = rep(src, 'const run = (sc, code) => {', 'const run = (sc, code) => { __n("row run");');
src = rep(src, 'const mine = shared ? used.filter((c) => !shared.has(c)) : used;', 'const mine = shared ? used.filter((c) => !shared.has(c)) : used; __n("used", used.length); __n("mine", mine.length); __n("cands", cands.length); if (process.env.SN_MINE) console.error(mine.slice(0, 30).join("\\n"));');

if (src.includes('const vals = rowFns ? progOf(nodes, L)?.(sc) : undefined;')) src = rep(src, 'const vals = rowFns ? progOf(nodes, L)?.(sc) : undefined;', 'const vals = rowFns ? progOf(nodes, L)?.(sc) : undefined; if (vals) { __n("row program calls"); __n("row program values", ROW_PARTS.get(nodes)?.list.length ?? 0); }');
if (src.includes('const mine = this.placedUnit ? unitCands(this.placedUnit, this.tplEls, this.fns) : null;')) src = rep(src, 'const mine = this.placedUnit ? unitCands(this.placedUnit, this.tplEls, this.fns) : null;', 'const mine = this.placedUnit ? unitCands(this.placedUnit, this.tplEls, this.fns) : null; __n("unit cands " + (this.collecting() ? 1 : 2) + (this.placedUnit ? (mine ? " hit" : " miss") : " none")); __n("tplEls" + (this.collecting() ? 1 : 2), this.tplEls.size); __n("unit list", mine?.list.length ?? 0);');
src = rep(src, 'const mine = cx.placedUnit ? unitCands(cx.placedUnit, cx.tplEls, cx.fns) : null;', 'const mine = cx.placedUnit ? unitCands(cx.placedUnit, cx.tplEls, cx.fns) : null; __n("unit cands " + (collecting(cx) ? 1 : 2) + (cx.placedUnit ? (mine ? " hit" : " miss") : " none")); __n("tplEls" + (collecting(cx) ? 1 : 2), cx.tplEls.size); __n("unit list", mine?.list.length ?? 0);');
src = rep(src, 'const run = (code) => {', 'const run = (code) => { __n("top run");');
src = rep(src, 'get: (_, p) => (p === t.item', 'get: (_, p) => (__n("row proxy get"), p === t.item');
src = rep(src, 'const rowsOf = (t, items, key, sc, out, recs) => {', 'const rowsOf = (t, items, key, sc, out, recs) => { __n("rows walked", items.length);');
src = rep(src, 'const render = (tid, rec) => {', 'const render = (tid, rec) => { __n("templates rendered");');
src = rep(src, 'function writeFirstPaint(el, kind, name, v, fresh = false) {', 'function writeFirstPaint(el, kind, name, v, fresh = false) { __n("writeFirstPaint " + kind);');
}
return { ...r, source: src + '\n;globalThis.__snInstr?.(Compiler);\n' };
}
if (url.endsWith('/dist/compiler/index.js')) {
const src = String(r.source ?? readFileSync(new URL(url)));
return { ...r, source: src + '\n;compile = globalThis.__snWrap ? globalThis.__snWrap("compile()", compile) : compile;\n' };
}
return r;
if (file === 'compile.js') tail.push('globalThis.__snInstr?.(Compiler);');
if (C && file === 'first-paint.js') src = COUNT + rep(src, 'function writeFirstPaint(el, kind, name, v, fresh = false) {', 'function writeFirstPaint(el, kind, name, v, fresh = false) { __n("writeFirstPaint " + kind);');
if (file === 'index.js') tail.push('compile = globalThis.__snWrap ? globalThis.__snWrap("compile()", compile) : compile;');
return tail.length || src !== src0 ? { ...r, source: src + '\n;' + tail.join('\n') + '\n' } : r;
}
5 changes: 4 additions & 1 deletion bench/tools/instr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const cpu = process.env.SN_CLOCK === "cpu" ? () => { const u = process.threadCpu
let depth = new Map();
function wrap(name0, f) {
return function (...a) {
const name = name0 === 'compile()' || name0 === 'decideFor' || typeof this?.collecting !== 'function' ? name0 : name0 + (this.collecting() ? '#1' : '#2');
// a method's compiler is `this`; a stage function's is its first argument
const cx = this?.constructor?.name === 'Compiler' ? this : a[0]?.constructor?.name === 'Compiler' ? a[0] : null;
const name = name0 === 'compile()' || name0 === 'decideFor' || !cx || !globalThis.__snCollecting ? name0 : name0 + (globalThis.__snCollecting(cx) ? '#1' : '#2');
const d = depth.get(name0) ?? 0;
if (d) return f.apply(this, a);
depth.set(name0, 1);
Expand All @@ -19,6 +21,7 @@ function wrap(name0, f) {
};
}
globalThis.__snWrap = wrap;
/** must match hooks.mjs; a Compiler method is wrapped here, a stage module's function by the load hook */
const METHODS = (process.env.SN_METHODS ?? 'decideFor,settle,prerender,worklist,fileConstants,writtenState').split(',');
globalThis.__snInstr = (C) => {
for (const m of METHODS) if (C.prototype[m]) C.prototype[m] = wrap(m, C.prototype[m]);
Expand Down
Loading
Loading