Repository navigation
Bring derived facts forward, hash less, drop unused facts indexes (#145) - #163
Open
QuintinBotes wants to merge 4 commits into
Open
QuintinBotes wants to merge 4 commits into
QuintinBotes wants to merge 4 commits into
Conversation
A changed re-map recomputed every derived fact from the whole graph (Graph.fromStore plus every component). Projection now returns the node and edge rows it wrote or deleted, and updateDerived works from those: components and their strict parts depend only on IMPORTS edges, and the build check on package containment, packages and DEPENDS_ON, so a change to any of these still recomputes everything. Otherwise only the node-level rows of changed modules, and the components and declared-only edges holding a module whose type, path, test flag or language changed, are worked out again, from the store. Rows keep their generation and the _done row names it (DERIVED_VERSION 3), so nothing else is rewritten; a kind whose key set changes is written again in key order. The full recompute reads only the edge types derived facts use. Tests: incremental-derived compares updated rows, in rowid order, with a full recompute after hand-made node and edge changes; incremental-link adds cycles in C#, JavaScript and Python and checks each step against a cold map and which path derived facts took. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- canonicalJSON returns a value already in canonical form as it is
instead of copying it. Cached facts are stored canonical, so hashing
every fact id in projection no longer copies every attrs object. The
output is unchanged (a test covers integer-like keys, holes, undefined
members and unsorted parts under sorted ones).
- Projection's merge pass skips an edge fact that no change touches
without building its id.
- An empty cache row ('[]', most rows of contracts, di and security) is
not parsed.
- A linker's saved state (the previous signatures of every path) is read
and worked out only when the linker asks for it; most keep none.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
facts_subject, facts_path and facts_generation are read by no query (lookups go by id, and search by object). They were about 11% of the MewsSystems/mews store (353 MB of 3.1 GB) and 6% of the synthetic 50k store, and every fact written maintained them. Migration 4 drops them and the DDL no longer creates them. It does not raise schema_version: an older release that opens the store creates them again and loses nothing, and the next open here drops them again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/benchmarks.md: the 50k gate, main and this change back to back (changed / no change 23.3 to 17.6, store / tree 50.0 to 46.8), the mews one-file edit (30 to 44 s to 23 to 27 s, store after a cold map 3.1 to 2.75 GiB, same rows as a cold map), and why reading every file's facts, projecting only changed facts and incremental JavaScript and Python linking are not done here. CHANGELOG entries and a migration note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #144 for #145. Derived facts are now brought forward from the rows projection changed instead of being recomputed from the whole graph, hashing fact ids costs about half the CPU, and three facts indexes nothing reads are dropped. A 10-file re-map at 50k went from 12.0 s to 8.8 s, and a one-file edit on MewsSystems/mews from 30 to 44 s to 23 to 27 s. Neither #145 target is met: the changed / no-change ratio is 17.6 (bound 2), and the store is 46.8 times the tree (bound 3). What is left runs over the whole repository for reasons the design here cannot remove soundly. They are listed below.
Part of #145
Design
Derived facts (
runtime/graph/derived.mjsupdateDerived).projectnow returns the node rows it wrote or deleted (before and after) and the edges it wrote or deleted. Components and their strict parts depend only on IMPORTS edges, and the build check only on packages, package containment and DEPENDS_ON. A change to any of these recomputes everything, now reading only the four edge types derived facts use (Graph.fromStore(store, { edgeTypes })). Otherwise the components stand, and only these are worked out again from the store:public_surface,test_code,ownership) of changed modules and of modules whose OWNED_BY edges changedRows keep the generation they were written at, and the
_donerow of a generation names it (DERIVED_VERSION3). An update therefore rewrites only the rows that changed. A kind whose key set changes is written again in key order, because readers take rows by rowid. The summary'sderivedreportsupdated,recomputedorkept.Hashing and reading.
canonicalJSONreturns a value already in canonical form as it is, instead of copying it. Cached facts are stored canonical. The output is unchanged; the change is covered by a 400k-value fuzz run against the old implementation and a unit test.Store (migration 4,
drop-unused-fact-indexes, non-breaking).facts_subject,facts_pathandfacts_generationare read by no query. Lookups go by id, and search goes by object.schema_versionstays 3, so 0.4.0 can still write the store. It creates the indexes again, and the next open here drops them.Rejected or not done.
contracts, and the member-attribute drop all change other files' facts after loading. What a file contributes is therefore not a function of its own cache row.JSON.stringifyas a fact fingerprint. It needs another column and saves less than the canonical fast path.Targets
idbench: 1.5 to 1.9 s vs 3.5 to 3.7 s CPU for 376k fact ids, alternated in one process. Projection 2.9 → 2.7 s at 50kMeasurements
Apple M5 Max, Node 26.13. Other projects' agents kept the load average between 8 and 88. Pairs were run back to back, and only the calm pair (load 8 to 10) is compared.
node scripts/bench.mjs --sizes 50k --gate:main, first pairmain, second pairThe branch's 10-file re-map in the second pair: census 0.4 s, extraction (reading cached facts) 2.0 s, link 3.2 s, discovery 0.3 s, projection 2.7 s, derived under 0.1 s.
mainhad the same phases plus about 2.9 s of derived facts.MewsSystems/mews (30.8k files, 210,713 nodes, 1,085,342 edges),
unknot mapfrom the CLI. A// touchcomment is appended toEnterprise.csand committed, alternatingmainand the branch on two copies of the same store (load 12 to 23):mainTesting
Equality with a cold map:
New and extended tests:
tests/unit/graph/incremental-link.test.mjsadds import cycles in C#, JavaScript and Python, with one cycle across build units and a CODEOWNERS file. Each step is compared row by row with a cold map. The steps are:Each step also checks whether derived facts were
updatedorrecomputed.tests/unit/graph/incremental-derived.test.mjs(new) changes stored node and edge rows by hand and compares the updated rows with a full recompute, in rowid order. The changes:It also checks that an import, package, containment or DEPENDS_ON change is not brought forward, and that the four edge types are enough.
tests/unit/policy/core-primitives.test.mjs: canonical JSON of partly canonical values.tests/unit/state/migrations.test.mjs: migration 4 drops the indexes, including after an older release has recreated them, and keeps schema 3.Mutation checks. Each mutation broke one of the new tests:
Commands:
npm test: 3,680 tests, 3,664 passed, 9 skipped, 7 failed. All 7 failures are intests/unit/daemon/remote.test.mjs("CA signature digest algorithm too weak", local LibreSSL) and fail the same way onmain.node scripts/upgrade-test.mjs --count 3: 3/3 (v0.3.2, v0.3.3, v0.4.0).Migration notes
Migration 4 runs on first open. It is quick and keeps schema 3. Derived facts are recomputed once by the first map after the upgrade. An existing store keeps the pages the dropped indexes freed and reuses them for later writes. A new store is smaller.
🤖 Generated with Claude Code