Reduce high-volume source-fact publication with typed COPY #41
Labels
No labels
area/cli
area/core
area/database
area/indexing
area/query
type/epic
type/feature
type/foundation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
JayKobe6k/ClariTree#41
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem and impact
After typed COPY was introduced for source anchors and semantic value nodes in #40, ClariTree still publishes the highest-volume source-fact nodes and structural relationships through prepared
UNWINDparameter batches. On representative 40- and 200-translation-unit workloads these remaining writes dominate LadybugDB publication time. Index creation and updates therefore spend avoidable CPU and native-allocation work converting typed Rust records into wide parameter structures.Environment and workload
32959f55abed0b7bd92d94670fcf9c9abb452a1elbug0.20.2melee-event-matchat6b6f8a8a987c2e871b8b96baa863aaa99e406f33tests/profile_lineage.rsMemorySwapMax=0, explicit memory limits, and runtime limitsReproduction after building the release profile test:
Baseline and profiling evidence
The 40-TU baseline persisted 28,375 definitions, 28,847 uses, 62,693 lineage relationships, and 729,601 source facts in 33.008 s and 33.797 s, a 33.403 s midpoint, at approximately 2.0-2.1 GiB peak RSS.
Three interleaved candidate runs completed in 22.774 s, 22.293 s, and 21.414 s. The 22.293 s median is 33.3% below the baseline midpoint, with identical semantic and persistence counts and approximately 1.2 GiB peak RSS. A final exact-tree run with the 4096 MiB compatibility default completed in 23.567 s at a 1.1 GiB cgroup peak with no swap.
A controlled 200-TU comparison produced identical 169,045 definitions, 180,182 uses, 400,939 lineage relationships, and 4,738,745 source facts:
32959f5This is a 37.7% persistence-time reduction and approximately 10.5% lower peak memory.
A final 128 MiB buffer-pool run was excluded: LadybugDB returned
Unable to allocate memory! The buffer pool is full and no memory could be freed!after a 1.1 GiB process peak. This confirms that the buffer-pool setting is not a total RSS limit and that undersized pools may fail publication, as documented by #39.Root cause
SymbolObservation,SymbolReference, andOperation: source node writers.LIST<STRUCT>parameters for every configured batch: parameter batching.The causal mechanism is repeated construction, conversion, and query execution for wide native parameter structures. Bounded typed CSV COPY removes that conversion path while preserving explicit schema targets and releasing each temporary import file after one chunk.
Proposed implementation
SymbolObservation,SymbolReference, andOperationnodes.Alternatives considered:
Expected benefit, confidence, and risks
Acceptance criteria
Related: #38 owns bounded persistence mapping, #39 owns buffer-pool configuration, and #40 introduced typed COPY for source anchors and semantic value nodes.
JayKobe6k referenced this issue2026-09-11 12:55:49 +00:00
Implemented and pushed in
b9354026f4. The pinned 40-TU workload improved from the 33.403 s baseline midpoint to a 22.293 s candidate median (33.3% lower), and the 200-TU workload improved from 217.743 s to 135.751 s (37.7% lower), with identical source-fact and semantic counts. Peak memory also decreased. Full Nix formatting, Clippy, all-target/all-feature tests, rustdoc, and Windows cross-compilation pass.