Skip to content

Estate read stays ~35s after #306 — per-member chant compose dominates, not concurrency #307

Closed

Description

@jhgaylor

First: thank you for #306 (bounded estate-read pool). It fixed the OOM decisively — on our cluster behold went from spiking past 6 GiB and OOMKilling mid-read to a stable ~812 MiB, 0 restarts. 👏

But the read latency is essentially unchanged — the bound stopped the thrash-to-OOM without making the compose faster.

Measurements (behold a2710adc, arm64 k3s)

An 11-member estate (~282 nodes), GET /api/diff?env=home, repeated warm reads:

read time size
1 (cold) 44.7 s 188 KB
2 37.1 s 188 KB
3 33.5 s 188 KB

Memory held ~812 MiB throughout (great). CPU ~0.85 cores.

Analysis

The read spawns one chant subprocess per estate member and composes each. The #306 pool now bounds how many run concurrently — which is exactly what fixed the memory blow-up — but the total work is ~11 per-member composes at a few seconds each, and with the bound they run close to serially, so wall-clock stays ~35 s. Concurrency was the memory problem; per-member compose cost is the latency problem, and they're separate.

Possible directions

  • Reuse a warm/in-process chant compile instead of a cold subprocess spawn per member (spawn + module load looks like the bulk of each member's cost).
  • Cache per-member composed IR and recompose only members whose source/drift changed (incremental reads).
  • Now that peak memory is bounded, allow a higher pool width when headroom exists — trade the freed memory back for parallelism.

Impact

~35 s per estate read makes an agent's diagnosis loop slow (multiple reads per incident) and forces live dashboards to read cluster state from kubectl instead of behold. Sub-5 s would make behold viable as the live source.

Happy to grab a profile/flamegraph of a single read if useful — just point me at how you'd want it captured.

Activity

  1. lex00 commented on Aug 30, 2026

    @lex00
    Contributor

    #312 (merged) takes the source half of the estate read out of the warm path. Profiled on a synthesized 11-member estate: ~85% of each member read was fixed spawn + CLI module-load cost (~750ms of ~900ms), so the fix is to not spawn at all for a member whose source didn't change — a per-member source-IR cache keyed on a full file stamp (path+mtime+size hash), the resolved chant bin+version, and the exact graph options, invalidated by the same #297 source watcher the estate already runs. Live/overlay reads are never cached — a cluster moves with nothing on disk to notice — so /api/overlay's N bindings spawns go warm-free while its N live spawns stay honest.

    Measured on the synthetic estate: warm composed read 3615ms → 5ms; one edited member re-reads only itself (920ms). Cold is unchanged. BEHOLD_ESTATE_IR_CACHE=0 disables it outright.

    One thing worth confirming from your side: this issue names GET /api/diff?env=home, but in current source that route is a single-project chant lifecycle diff on the served projectDir, with no estate fan-out — the 188KB/282-node payload in your table looks like the composed estate IR from /api/graph///api/overlay, which is the path #312 speeds up. If your 35s really is /api/diff, that endpoint has no estate branch at all today and that would be its own issue. Ships in the next release either way.

    🤖 Claude Code — https://claude.ai/code/session_01Rfs1mLVWmwginHnDTg75sG

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