Files
CatoandClaude Opus 5 bdf9a2988b perf(engine): index the corpus, and give every entity a path to the KPI (#62)
Two halves of the same idea: the web is about to get much bigger, so the
lookups have to be cheap, and the reason for holding it at all has to be
visible from any node in it.

**Indexing.** Measured before touching anything: `allEntities()` cost 22ms per
call, and every lookup called it and then linear-scanned the result, so a single
entity lookup cost 19ms. At 268 entities that is invisible; at ten times that it
is fatal, because the cost is the rebuild multiplied by the scan and grows with
the square of the corpus while feeling fine right up until it does not.

The corpus is derived from static config and cannot change within a process, so
it is built once and served from maps: by id, by kind, and by name-or-alias.
Relations are materialised by endpoint, both directions together — which is also
what makes the single declaration safe, since the forward and inverse readings
are produced from the same relation and cannot diverge.

`allEntities()` x200: 4,422ms to 0ms. 13,400 entity lookups: 43ms, from what
would have been about four minutes. A test guards the structure (identity, not
equality, proves it is built once) rather than a stopwatch reading, with bounds
set to catch a return to linear scanning — orders of magnitude, not drift. A
second test asserts the fast path answers exactly what the slow one did.

**The KPI spine.** The site's model is loops: design, build, measure, turned as
fast as the slowest thing in the way allows. So the question worth asking of any
company, rule, mandate or country is not "is it important" but "which loop does
it hold up, and through what". That is a traversal — entity, to the bottlenecks
it is joined to, to the loops those gate — and it is affordable precisely
because of the indexing above.

"What this holds up" replaces the bottleneck-only "Which loops wait on it": the
traversal is identical for every kind, so it is one module rather than one per
kind. Each row carries the evidence of the join it travelled, because the
strength of "this firm holds up that loop" is the strength of its weakest hop.

What it must never do, and a test holds: severity is a dated judgement on a 0-12
scale, and judgements are not added together. A composite reads as a measurement
of the world and is not one, so a loop reports the WORST single judgement — the
test asserts that figure always equals one of its gates.


Claude-Session: https://claude.ai/code/session_01Y6ecRd91ZsPPcjuNkKTFV2

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 06:57:53 -07:00
..