Skip to content

perf(reconcile): write a run's entity events in one statement, not one transaction each (#1409) - #1417

Merged
athvin merged 1 commit into
mainfrom
fix/1409-batch-entity-events
Nov 29, 2026
Merged

athvin merged 1 commit into
mainfrom
fix/1409-batch-entity-events

Conversation

@athvin

@athvin athvin commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Closes #1409

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

run_reconcile writes a run's entity events in one statement: they're staged in a session temp table through a DuckDB appender and written by a declared INSERT … SELECT (entity_event/create/append_from_src, ordered by seq). The per-event append statement 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 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 min while match took 5 s, and the long-held writer slot made three deploys' er-tenant-migrate hooks time out.

Proof

make check exit 0.

Measured locally, same 260k corpus, release build, 4 threads:

before after
reconcile >50 min, never finished 12.9 s
whole run_all — 3 min 45 s

The 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-060338df4848 on brians-MacBook-Pro · 2026-11-29T08:42:55Z

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

…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
athvin merged commit deec8f5 into main Nov 29, 2026
44 checks passed
@athvin
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

1 inactive deployment
marketing-preview — cb84f4a1 Deployed Nov 29, 2026 by athvin via remove closed PR previews #149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reconcile takes >35 min on a 260k-record delivery while match takes 5 s

2 participants