Skip to content

chant costs ~800ms per invocation before it does any work, and an estate reader pays it once per member per read #2481

Open

Description

@lex00

What

chant <verb> costs about 800ms before it does anything, and a consumer that reads an estate pays that once per member per read.

behold shells the project's own chant — deliberately, because members pin different versions — so an N-member estate is N processes. On the 11-member Kubernetes estate behold measured in INTENTIUS/behold#367, that is ~8.8 seconds of CLI startup before a single line of graph work or one call to a substrate.

This issue is the ask INTENTIUS/behold#424 exists to make: not "behold is slow", but "here is the share of it that is chant's, measured".

The floor, measured

Mean of 3 runs each, chant 0.61.0, macOS arm64, warm filesystem. chant --help parses argv and exits — it does no graph work at all, so it is the floor every other invocation stands on.

invocation wall floor's share
chant --help (parse argv, exit) 799 ms —
chant graph <8-node example> --format ir 1048 ms 76%
chant graph <3-lexicon example> --format ir 1513 ms 53%
chant graph . --live --overlay --env prod (1 member, AWS on a local Floci) 1277 ms 63%

So on a small member, three quarters of the read is module load and argv parsing. The content cost is 249 ms for the 8-node example and 714 ms for the three-lexicon one; the live half against an emulator adds ~478 ms over the floor.

Per-member figures from behold's own read ledger agree: a 5-root Terraform member reads at 1144 ms and 1123 ms, queuedMs 0 both times, against the same ~800 ms floor.

Why it multiplies

behold cannot amortise it. It shells the project's own chant precisely because two members of one estate may pin different chant versions, so a single imported chant would graph one member's source with another's compiler. That is stated in src/member-ir.ts and it is not something behold intends to change.

What behold has already done, so this is not an ask about caller behaviour:

  • a process-wide FIFO read budget, two concurrent by default, with in-flight sharing by read identity and per-subscriber cancellation (behold#367);
  • a per-member source-IR cache keyed on source stamp, resolved chant and graph options, so a member whose source has not moved does not spawn at all (behold#307);
  • removal of the browser's unconditional 3/8/15s follow-up reads (behold#367).

The remaining cost is per invocation, and it is chant's.

The other half, cited not re-measured

behold#367 measured chant's per-read Kubernetes discovery on an 11-member estate: 153s to observe, 147s on a repeated read with the source cache warm, and 217 API requests in 28s from a single member. Those figures are that issue's, reproduced here for scale rather than re-run — reproducing them needs a cluster, and this machine's kube context belongs to something else.

The floor above is fresh and side-effect-free; the discovery figure is prior work, attributed.

The ask

  1. Is the ~800 ms startup reducible — a lazy CLI module graph, a smaller entry point for read verbs, or a compiled entry rather than tsx on the published bin? A read verb that answered in 200 ms would take ~2.2s off an 11-member estate before anything else changed.
  2. Is there an interest in a long-lived read mode — one process answering many graph reads for one project — that would let a consumer amortise the floor without importing chant and losing per-member version fidelity?
  3. Separately, the Kubernetes discovery cost in behold#367 is chant's k8s reader, not behold's caller behaviour. Worth its own issue on that side if the numbers above are accepted.

Method, so it can be re-run

chant --help                                          # the floor
chant graph <project> --format ir                     # source evaluation
chant graph <project> --live --overlay --env <env>    # source + substrate

behold's own per-read breakdown is on GET /api/doctor?reads=1 (behold#420/#421): source and live phase totals, per-member samples with running and queued milliseconds, and a count of members the ledger cannot see.

Refs INTENTIUS/behold#424, INTENTIUS/behold#419, INTENTIUS/behold#367.

Activity

  1. lex00 commented on Sep 18, 2026

    @lex00
    ContributorAuthor

    Partial measurement, and what I could not measure, from the behold side (INTENTIUS/behold#424).

    The tooling floor, measured

    The published bin is exec npx tsx "$MAIN_TS" "$@", so every invocation pays two layers before a line of chant loads. On macOS arm64, warm, mean of 3-5:

    node -e "" 30 ms
    tsx -e "" (the bin directly) 170 ms
    npx tsx -e "" 291 ms

    So npx costs roughly 120 ms over invoking tsx directly, and tsx costs roughly 140 ms over bare node. Against the ~800 ms chant --help I measured for #2481, that is about 15% of every invocation spent resolving a binary the package already depends on, and another ~17% in the transpiler before any chant module is read.

    The remaining ~500 ms is chant's own module graph being transpiled and loaded, which is the part that actually needs the lazy-entry work the issue describes.

    What I did not do, and why

    I did not change the bin. The obvious move is to resolve tsx directly rather than through npx, but it is not a one-liner worth guessing at: npx tsx works regardless of hoisting, and a direct path (../../.bin/tsx) or a node --import tsx entry each make assumptions about the consumer's install layout that want testing against a real npm i @intentius/chant rather than a workspace checkout. just smoke-npm is presumably the lever for that.

    I also could not produce a reliable before/after. My machine stopped being a usable measurement environment partway through — the same chant --help that measured 799 ms this morning was exceeding ten minutes by the afternoon, after a full just check and a lexicon regen. Shipping a perf change I cannot measure would be the wrong thing, so the numbers above are the contribution rather than a patch.

    Suggested split

    The npx layer and the module graph are independent and differently sized. The first is a packaging question with a ~120 ms answer and a smoke test to prove it; the second is the real work. Worth two issues if that matches how you would take it on.

    Refs INTENTIUS/behold#424.

  2. lex00 commented on Sep 19, 2026

    @lex00
    ContributorAuthor

    Correcting my comment above, and replacing the part I said I could not do.

    The correction

    I wrote that my machine "stopped being a usable measurement environment" and that I could not produce a reliable before/after. That was wrong, and the mistake was mine rather than the machine's: I had been timing the chant source checkout, where every invocation transpiles the whole monorepo (5:33 wall, 320 s user CPU). The published package — what users actually run — measures cleanly and repeatably at ~800 ms. I conflated the two and blamed the hardware.

    So the experiment I declined to run was runnable the whole time. Here it is.

    The result

    Three bins against the same installed @intentius/chant, --help, mean of 7 warm runs on macOS:

    variant
    npx tsx main.ts (ships today) 836 ms
    node node_modules/tsx/dist/cli.mjs main.ts 701 ms
    node --import tsx main.ts 590 ms
    node --import tsx/esm main.ts 534 ms

    The floor I measured earlier holds up: npx is ~250 ms of bin resolution, and tsx's own CLI then spawns a second node. Pointing --import at tsx's loader collapses both.

    Confirmed in a clean node:24-slim container against a real npm install of the packed tarball: 598 ms → 425 ms, −29%, with all 326 lines of --help diffing clean. On a real read rather than --help, graph <project> --format ir goes 928 ms → 696 ms.

    tsx/esm is the fastest but the wrong choice: it registers only the ESM hook, and chant calls createRequire in about ten places including the two that load user files (config-import.ts, cli/plugins.ts). --import tsx keeps the CJS hook and is still ~30% off.

    On the lever I said I'd need

    I said just smoke-npm was the thing to prove this against a real install layout rather than a workspace checkout, which is why I wouldn't guess at a patch. I've now run it: 72 passed / 6 failed, identical before and after. The six are the pre-existing k8s microservice example failures (ingress.ts, Cannot read properties of undefined (reading 'split')) and are unrelated.

    behold's own suite — 2081 tests, most of which shell this bin — also passes unchanged, 4.0 s → 3.5 s wall.

    PR: #2485. It only addresses the per-invocation floor; the "once per member per read" half of this issue, which is the scheduler and cache question, is untouched and is the larger win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions