Repository navigation
perf(reconcile): write a run's entity events in one statement, not one transaction each (#1409) - #1417
Merged
Conversation
…e transaction each (#1409) run_reconcile appended every lifecycle event with its own INSERT, so every event was its own DuckLake transaction: parse, plan, commit, fsync. A sample of the stuck process showed it all in entity_event::create::append. On er-dev a 260k-record delivery's reconcile ran past 35 minutes (and locally past 50) while match took 5 s. The long-held writer slot also blocked three deploys' tenant-migrate hooks. The events are now staged in a session temp table through a DuckDB appender and written by one declared INSERT ... SELECT (entity_event/create/append_from_src, ordered by seq). The per-row statement had no other caller and is retired. Ids, seq, details and hashes are unchanged. Measured locally, same corpus, release build, 4 threads: reconcile >50 min (never finished) -> 12.9 s; the whole run_all is 3m45s. The lake tiers that assert the ledger pass: er-cli 68/68, pg_entity_events, pg_merge_group, pg_unmatch, pg_launch_proof. Co-Authored-By: Claude Opus 5.5 <[email protected]>
athvin
temporarily deployed
to
marketing-preview
November 29, 2026 07:02 — with
GitHub Actions
Inactive
athvin
added a commit
that referenced
this pull request
Nov 29, 2026
…r the members (#1424) (#1427) reconcile_plan's overlap matrix intersected every new group with every old entity: groups x entities BTreeSet intersections, almost all empty. An incremental reconcile of a 260k delivery over a 260k corpus therefore ran past 15 minutes on er-dev at 100% of one CPU, after #1417 had already made the full path take seconds. Found by #561's live proof; a local sample of the incremental run showed it all in reconcile_plan. overlap_matrix now indexes each record's old entities once and drops each new group's members into their cells: O(total members). The index keeps every entity a record is in, so the result equals the pairwise definition even if p_old were not a partition. overlap_matrix_equals_the_pairwise_definition pins that, including a record in two entities, a departed record and new ones. Local repro (debug build): an incremental reconcile of 260k over 260k went from never finishing (sampled, then killed) to 27.7 s. er-reconcile's goldens and the er-cli lake tier (68/68) pass. Co-authored-by: bmoore813 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This branch was previously deployed
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.
Closes #1409
What
run_reconcilewrites a run's entity events in one statement: they're staged in a session temp table through a DuckDB appender and written by a declaredINSERT … SELECT(entity_event/create/append_from_src, ordered byseq). The per-eventappendstatement had no other caller, so it is retired. Event ids,seq, details and hashes are unchanged.Why
Each event was its own INSERT, which made each one its own DuckLake transaction (parse, plan, commit, fsync). A
sampleof the stuck process showed it all inentity_event::create::append. On er-dev a 260k-record delivery's reconcile ran past 35 min while match took 5 s, and the long-held writer slot made three deploys'er-tenant-migratehooks time out.Proof
make checkexit 0.Measured locally, same 260k corpus, release build, 4 threads:
run_allThe ledger-asserting tiers pass: er-cli e2e 68/68,
pg_entity_events,pg_merge_group,pg_unmatch,pg_launch_proof.Risk & rollback
Same rows, written in one transaction instead of thousands. A failure mid-write now writes no events rather than some. Rollback:
git revert <merge-sha>.Post-merge ledger
Closed by: agent · session
Claude Code:24d16c2e-fec6-49d8-9797-060338df4848onbrians-MacBook-Pro· 2026-11-29T08:42:55Zmainis green with this change on it — the merge SHA, and the runthat proves it. A later head SHA with this commit as an ancestor counts;
a cancelled run with zero jobs does not: — deec8f5; its own rust 46236145854 was cancelled by the next merge's concurrency group; rust 46242304135 on 7a8145b (contains this commit) success
imagesbuilt, or correctly never ran because nothing that goes intoan image changed: — success, run 46236145810
deployconverged — proved by a line the running process emitted, notby the image digest and not by the workflow conclusion: — the deploy of 71c1be1 (46236973907), which contains deec8f5, succeeded; live: on er-dev the p3live ingest/standardize/match all completed, and the remaining incremental slowness was a second cause, Incremental reconcile is O(groups × entities): every new group intersected with every old entity #1424
deploy,drift,kind's nightly leg) is green, or knowingly red for a reason that is notthis change: — infra, devcontainer success
Donethrough the automation rather than byhand, and the issue closed: — reconcile takes >35 min on a 260k-record delivery while match takes 5 s #1409 CLOSED by perf(reconcile): write a run's entity events in one statement, not one transaction each (#1409) #1417 via automation
(a skill, a reference, memory) — or nothing new was learned: — memory long-dev-job-blocks-deploy-hook; per-event INSERTs are one DuckLake transaction each, so batch through a temp table
Specific to this change
Context — plan, discoveries, measurements, files
Plan
Discoveries
Measurements
Files
Remaining wall time is ingest (1m46s) and standardize (1m36s) at 260k; those matter for #558's 10M run. Adds
duckdb(workspace version) as an er-cli dependency, for the appender.🤖 Generated with Claude Code