qat

Optimization

What Qat does to your code so that the page ships less and runs less. It falls in three parts: what it does on its own, what it does from a profile you record, and what you ask for. Each optimization keeps what the page does: the compiler's test suite explores each one's corpus with it and without it, and the two models must be equal. And none of them sends anything anywhere (the rule).

Automatic: nothing to write

The compiler, on every component (qatjs dev keeps the ones that would hide a value from the debugger off; a build has them all):

What it sees What it emits
a const taken once and shown as text inserted once: no effect (QX-SNAPSHOT's case)
class:sel={sel === r.id} (or style:, {if}) in a {for} row one selector for the list: a selection costs two rows, not all
several bindings of one element on the same signals one effect for them
a {for} row whose bindings are cheap reads (signals, props, getter calls without arguments, comparisons) one effect for the row, each value written only when it changed: one computation per row, not one per binding
a state nothing writes a constant; a literal folds into the template (qatjs check --unused lists them)
a prop every call site passes a value that never changes the component compiled with that prop constant (from every call site in the app)
a derived read in exactly one place its body, inlined there: one node, not two

qatjs compress, over the whole app:

  • What nothing has opened yet is not in the first load. A component shown only behind a closed {if} (a dialog, a calendar's picker) is loaded on its first render: a render one tick later, the same page (On first render). This is lazy({ on }), done for you.
  • The seed holds what the page cannot read back. Route data that the page shows only as an element's innerHTML/textContent is left out of the resume seed and read back from the server's HTML (a docs page's HTML: −20 %).
  • mode: 'auto' picks each route's render mode from the render-mode checks, never one they fail. A route behind a guard gets 'client'; a route a check fails for (a browser API in what it renders) gets 'client'; every other route gets 'server' ('static' on a static host) (server rendering).
  • Exact route sets, the core trimmed to the units the app uses, content-addressed chunks (compress).

Every decision qatjs compress takes is in dist/report.json under decisions, with its reason; --analyze prints them.

From a profile: counted on your machine

shell3 lines
qatjs dev --count               # counters of your own sessions → qat.profile.json (git-ignored)
qatjs compress --profile qat.profile.json
qatjs check --suggest           # what the profile and the graph say could be cheaper

A profile is counters only: route visits and from → to transitions by pattern, each component's rendered and ever-seen counts. It holds no ids, URLs or values. (Its signals table is not filled by --count.) qatjs init lists the file in .gitignore; an app made before that adds it. --profile adds the profile's proposals to the report's decisions:

  • a prefetch where most navigations go;
  • a component rarely on screen, to load when visible ("below the fold");
  • routes visited back and forth, to merge.

They are proposed, not applied, each with the reason it is not applied yet (A build profile). --suggest lists states nothing writes (from the code), components rarely seen (from the profile), and each collection chain left as written, with why.

Opt-in: you write it

  • static(() => expr) runs at build, in Node, with the file's imports. Its result is a literal in place of the call, and the branches it chooses are folded (Build-time values).
  • derived(chain, { incremental: true }) runs a collection chain over a large deep store in delta mode: one element changed, only that element's part of the chain runs again. On a 10,000-row report that is about 0.02 ms for a price change, against milliseconds for the chain (Large collections). A state(static(…)) of 500 elements or more is known large without asking.
  • store({ cold: true }) lets a large store's unread fields go to IndexedDB and frees them; a read brings them back (Large stores). Kept pages (keep) do not go cold yet.

Nothing is sent anywhere

Qat never sends data to Qat. Any endpoint is the project's own; production collection is opt-in, identifier-free, counters only. qatjs dev --count posts its counters to its own dev server, which writes qat.profile.json in your project, and nowhere else. A test holds every code path of this layer to that: no network call outside the app's own endpoints (packages/toolchain/test/no-network.test.ts). The same rule is on vitals and compress.