Skip to content

perf(resolve): standardize the probe staged, serve warm calls from the file cache, drop per-call objects (#1429) - #1515

Merged
athvin merged 1 commit into
mainfrom
perf/1429-resolve-standardize
Dec 2, 2026
Merged

athvin merged 1 commit into
mainfrom
perf/1429-resolve-standardize

Conversation

@athvin

@athvin athvin commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Refs #1429

This change does not close #1429. That issue closes only after the 55-call er-dev measurement meets the wall p95 < 300 ms gate. It carries the no-ticket label for that reason.

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

What

  • Staged probe standardization. Resolve now standardizes its one probe record with int_std_records_sql_staged / acct_int_std_records_sql_staged. These use the corpus's own er_std::sql normalizers, routed through a new Share hook. Staged computes each repeated value once, as a column of a lower projection. Inline returns the original text, so the corpus standardization SQL is byte-identical: I verified this by diffing the person, person-with-rules and account renderings before and after.
  • No file I/O on a warm detached call.
    • detach_corpus turns on DuckDB's external file cache for local files (cache_local_files, VALIDATE_REMOTE) and the Parquet metadata cache.
    • It pins parquet_prefetch_column_gap. Otherwise the prefetch cost model opens the file to estimate throughput.
    • The detached corpus view is now registered once per file listing, not once per call.
  • Nothing left behind. Each call drops the views and tables it created. Before this, a kept session grew by 3 views, 3 tables and about 392 KB per call. predict_between also drops its hierarchy closure.

Why

The 2026-12-02 er-dev pass on f3cb5ede had server p50 411 ms: standardize_ms 227 and prefilter_ms 138. p3live is served by the detached path: an in-memory session with no catalog attached during a call. So neither stage made a catalog round trip.

  • Standardize was CPU. The inline rendering of one crm record extracts its 11 payload fields 83 times. phone alone is extracted 38 times, because null_semantics and the phone, name and address generators repeat their operands. DuckDB plans and evaluates every copy. Preparing the statement would not help: DuckDB 2.0.1 marks any prepared statement that reads a table always_require_rebind (optimizer.cpp:588), so it is re-planned on every EXECUTE. I measured EXECUTE at about 80 ms versus 45 ms for PREPARE.
  • Prefilter was EFS. The same prefilter takes about 5 ms locally. Its only file access is the per-call read_parquet of the hit files, which on er-dev is EFS.

Proof

  • New guard: a_warm_detached_resolve_reads_no_file_and_standardizes_each_field_once (er-cli lake e2e). It reads DuckDB's own QueryLog and FileSystem logs over one warm call, on er-dev's detached path. It asserts no OPEN or READ of a corpus file, each payload field extracted once, no growth in temp objects, and the same answer as the lake resolve.
  • Watched it fail first:
    • On HEAD's resolve it fails on the file I/O assertion: one warm call opened the corpus file 3 times and read it twice.
    • Mutated to the inline builder, it fails with first_name was planned 8 times.
    • With the cleanup removed, it fails with temp objects 69 != 64.
  • Equivalence: staged_standardization_equals_inline and staged_account_standardization_equals_inline (er-standardize). They build int_std_records both ways over every input in er-std's normalizer goldens, placed into every mapped field of every source. The person configs include plus-stripping, placeholders, a cleanse rule and a GB region. The check is except all in both directions. A mutation that conflates Staged entries fails both tests.
  • Analyser: the er-sql-check analyser plans both staged renderings to the same columns as the inline ones.
  • Gates:
    • DEDUPE_E2E_DUCKLAKE=1 cargo test -p er-cli: 74 passed, 1 ignored (the benchmark).
    • cargo test -p er-standardize -p er-std: pass.
    • The er-sql-check standardize plan tests: pass.
    • er-server pg_launch_proof against a local Postgres 16 (DuckLake tier, DuckDB-file lake, i.e. the detached path): pass.
    • make check: exit 0 (fmt, clippy, doc, entities-check, skills-check and the other gates, then cargo test --workspace: 1278 passed, 0 failed).

Risk & rollback

  • Staged rendering: it is used only for the probe. A normalizer added without a share call is still correct, just slower, and the equivalence test covers new goldens automatically.
  • File cache: it holds the compressed Parquet that resolve reads, in DuckDB's buffer pool, which is cgroup-bounded and evictable. Local entries are not revalidated, which relies on DuckLake data files being write-once; the session re-lists them on every catalog change.
  • Rollback: git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:cf299f4a-bafd-4f62-a459-2f495e05c5f2 on Mac · 2026-12-02T06:42:00Z

  • main is green with this change on it — the merge SHA, and the run
    that proves it. A later head SHA with this commit as an ancestor counts;
    a cancelled run with zero jobs does not: a1dd29d5. rust 46824529215, frontend 46824528808, infra 46824528947, devcontainer 46824528770 and images 46824528845 all success.
  • images built, or correctly never ran because nothing that goes into
    an image changed: images 46824528845 success on a1dd29d5.
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: deploy 46825081522 logged deploying a1dd29d512d9895c3622e590570f2f46fbdef74c, and both the dev and prod jobs succeeded. ci/er-api switched to blue (er-api@sha256:6edf36df…). That process's resolve timings lines show standardize_ms p50 28.3 ms on 55 calls, against 227 ms before. That is this PR's staged standardization running.
  • the push-only surface no pull request can pre-test (deploy, drift,
    kind's nightly leg) is green, or knowingly red for a reason that is not
    this change: deploy green, dev and prod. drift is knowingly red for reasons that predate this change: it has failed on every scheduled run since at least Nov 29 (46231663846, 46363578852, 46587395674, and 46821594846 on 71a493d, before this merge). blocked — kind's nightly leg hasn't run since the merge; it runs tonight.
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: deferred — Resolve latency: ~2.1 s p50 at 520k records because the corpus is materialised per request #1429 stays open, correctly. Its live gate is still missed: wall p95 515 / 459 ms over two 55-call passes, server request p95 344 ms. The next lever is the prefilter (below).
  • follow-ups are open for everything deferred here — numbers: deferred — Resolve latency: ~2.1 s p50 at 520k records because the corpus is materialised per request #1429 (prefilter on er-dev's EFS-backed corpus; attached-path file cache).
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned: the online-resolve section of er-server-control-plane/references/handlers-and-state.md (this PR). The live result, including that the prefilter did not drop, is on Resolve latency: ~2.1 s p50 at 520k records because the corpus is materialised per request #1429.

Specific to this change

  • er-dev 55-call pass on p3live after deploy: wall p50/p95 and the resolve timings medians, against standardize_ms 227 / prefilter_ms 138 / server p50 411 ms. The prefilter_ms drop is the EFS claim this PR could not measure locally. Done, 2026-12-02 06:36 and 06:38 UTC: two passes of 5 warm-ups + 55 calls on p3live/default (779,861 records, snapshot 29533, a temporary viewer key since revoked). Wall p50/p95 416/515 ms, then 413/459 ms, through a port-forward whose /healthz floor is 168 ms. Server resolve timings p50: standardize 28.3 (was 227), prefilter 122.7 (was 138; p95 185), prepare 5.4, predict 23.6, select 12.3, total 195.4 (was 411; p95 287, then 227 on pass 2). Server request duration p50/p95 240/344 ms. The EFS file-cache claim did not hold: the prefilter fell only 11%.
  • er-dev memory of the API pod after a long resolve run stays flat (the per-call leak is gone; the file cache grows to at most the compressed corpus). er-server in web-api-blue-9c6fdc855-jcp4f went from 721 MiB to 729 MiB across the second 60-call pass, which is flat; the 06:36 pass had already warmed it.
Context — plan, discoveries, measurements, files

Discoveries

  • The brief assumed a different path. It assumed er-dev's lake is ducklake:postgres: and served attached. p3live is not. Before fix(resolve): copy the membership through the catalog on refresh, and cache a refused detach (#1502) #1503 it logged persistent=false on 61/61 calls, which only the non-Postgres branch emits. It now logs persistent=true, which for a file catalog means the detached path. During a call that session has no lake attached, so there were no catalog round trips to remove.
  • No CSE under CASE. DuckDB's common-subexpression pass skips short-circuited CASE branches. The analyser already needed a 16 MB stack to plan the inline standardization.
  • Local files are not cached by default. DuckDB's external file cache skips local files unless cache_local_files is set ("the OS page cache already serves repeated reads"), which EFS defeats. CachingFileHandle::TryGetNetworkThroughput opens the file even when every byte is cached, which is why the prefetch gap is pinned.

Measurements

resolve_latency_at_scale (ignored er-cli test), 779,999 records, one thread, 20 timed calls after 5 warm-ups. Per-phase p50 / p95 in ms, from the resolve timings phases:

Phase Before (f3cb5ede) After
standardize 85.5 / 88.2 11.7 / 12.3
prefilter 5.4 / 5.8 4.6 / 4.7
prepare 5.2 / 5.4 5.1 / 5.4
predict 38.0 / 39.1 38.1 / 39.3
select 3.8 / 4.0 4.2 / 4.8
end-to-end call 141 / 144 64 / 66

Standardization statement alone, same probe: plan only (EXPLAIN) 58 → 12 ms, CTAS 84 → 11 ms. The staged SQL is 7.3 KB, against 20.3 KB inline.

Projection for er-dev (not measured): scaling standardize by the local ratio gives 227 → about 31 ms. If the prefilter loses its EFS reads it should approach its in-memory cost. That puts the server near or under 100 ms against the 150 ms headroom target. The remaining big phase is predict (23 ms on er-dev, 38 locally).

Files

  • rust/crates/er-std/src/sql.rs: Share, Inline and Staged, plus the _in variant of each generator.
  • rust/crates/er-standardize/src/lib.rs: Rendering, the staged SQL and builders, and tests/staged.rs.
  • rust/crates/er-cli/src/lib.rs: staged probe, CallObjects cleanup, cached corpus view, and file-cache settings in detach_corpus. The guard is in tests/lake_e2e.rs.
  • rust/crates/dedupe-core/src/incremental.rs: predict_between drops ancestors.
  • rust/crates/er-sql-check/src/stage.rs: plans the staged renderings.
  • .claude/skills/er-server-control-plane/references/handlers-and-state.md: the online-resolve reference.

🤖 Generated with Claude Code

…e file cache, drop per-call objects (#1429)

On er-dev, p3live's 411 ms server resolve spent 227 ms standardizing its one
probe record and 138 ms in the prefilter. p3live is served by the detached
path, so neither stage touched a catalog.

Standardize was CPU. The inline normalizer text extracts one crm record's 11
payload fields 83 times (`phone` 38 times). DuckDB plans and evaluates every
copy, and re-plans a prepared statement that reads a table on every EXECUTE.
`er_std::sql` generators now route repeated values through a `Share`.
`Inline` keeps the corpus SQL byte-identical. `Staged`, used only for the
probe, computes each value once in a lower projection. Locally at 780k
records on one thread, standardize drops from 85.5 to 11.7 ms p50.

The prefilter's only file access was the per-call read of the hit Parquet
files on EFS. `detach_corpus` turns on DuckDB's external file cache for local
files, with local revalidation off because DuckLake data files are write-once.
It also turns on the Parquet metadata cache and pins the prefetch gap, whose
cost model reopened the file. The detached corpus view is registered once per
file listing.

Each call now drops the views and tables it created; a kept session used to
grow by about 392 KB per call. `predict_between` drops its hierarchy closure.

The local end-to-end call drops from 141/144 ms to 64/66 ms (p50/p95).
a_warm_detached_resolve_reads_no_file_and_standardizes_each_field_once reads
DuckDB's query and file-system logs to pin all three changes, and fails on the
old code. staged_standardization_equals_inline holds the two renderings to the
same rows over every er-std golden input.

Refs #1429

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@athvin athvin added the no-ticket deliberately not tied to a board ticket; exempts the pull request contract label Dec 2, 2026
@athvin
athvin merged commit a1dd29d into main Dec 2, 2026
47 checks passed
@athvin
athvin temporarily deployed to marketing-preview December 2, 2026 06:25 — with GitHub Actions Inactive
athvin pushed a commit that referenced this pull request Dec 3, 2026
…key auth's connection (#1429)

On er-dev, #1515 brought standardize to 28 ms but the prefilter only fell from
138 to 123 ms. Serving the Parquet bytes from the file cache removed the EFS
reads, not the decode. Reading even one row decodes its whole row group, and a
probe's candidates span several of p3live's ~15 files.

Reproduced locally by writing the benchmark corpus in 15 files with the
probe's matches planted in five of them: the fetch went from about 2 to 21 ms.
Rewriting the cross-file OR as one per-file fetch with pushable filters changed
nothing.

On each corpus change the session now copies the whole corpus, with its
precomputed blocking keys, into a compressed in-memory database, and indexes
the keys. Each indexed lookup returns its candidates' rows directly; filtering
the copy by row id would scan every row group holding one. A warm call reads
no Parquet, on either path. At 780k records the copy holds 215 MiB, against
531 MiB as a temp table, and takes about 2.4 s to build once. The file-cache
settings from #1515 are removed, because they would only hold a second copy.
On the er-dev-shaped corpus, local, one thread: prefilter 25.2 -> 8.1 ms p50,
end to end 87/90 -> 69/73 ms p50/p95.

The handler spent ~42 ms outside the resolve stages, and opened two TLS
Postgres connections per request. The resolve route now opts in
(`ReuseKeyAuth`) to keeping the key extractor's connection and org row, so the
handler neither reconnects nor re-reads the org.

New log fields: `resolve request timings` (auth, lookup, blocking),
`setup_ms` and the prefilter's keys/lookup split on `resolve timings`, and
`resolve corpus cached` (build time, rows, memory), so the next er-dev pass
accounts for every millisecond.

a_warm_detached_resolve_reads_no_file_and_standardizes_each_field_once now
asserts a warm call runs no `read_parquet`, and fails on the previous code.
a_cached_attached_resolve_matches_the_lake_resolve covers the attached path
and its rebuild on a new snapshot.

Refs #1429

Co-Authored-By: Claude Opus 5.5 <[email protected]>
athvin pushed a commit that referenced this pull request Dec 3, 2026
…key auth's connection (#1429)

On er-dev, #1515 brought standardize to 28 ms but the prefilter only fell from
138 to 123 ms. Serving the Parquet bytes from the file cache removed the EFS
reads, not the decode. Reading even one row decodes its whole row group, and a
probe's candidates span several of p3live's ~15 files.

Reproduced locally by writing the benchmark corpus in 15 files with the
probe's matches planted in five of them: the fetch went from about 2 to 21 ms.
Rewriting the cross-file OR as one per-file fetch with pushable filters changed
nothing.

On each corpus change the session now copies the whole corpus, with its
precomputed blocking keys, into a compressed in-memory database, and indexes
the keys. Each indexed lookup returns its candidates' rows directly; filtering
the copy by row id would scan every row group holding one. A warm call reads
no Parquet, on either path. At 780k records the copy holds 215 MiB, against
531 MiB as a temp table, and takes about 2.4 s to build once. The file-cache
settings from #1515 are removed, because they would only hold a second copy.
On the er-dev-shaped corpus, local, one thread: prefilter 25.2 -> 8.1 ms p50,
end to end 87/90 -> 69/73 ms p50/p95.

The handler spent ~42 ms outside the resolve stages, and opened two TLS
Postgres connections per request. The resolve route now opts in
(`ReuseKeyAuth`) to keeping the key extractor's connection and org row, so the
handler neither reconnects nor re-reads the org.

New log fields: `resolve request timings` (auth, lookup, blocking),
`setup_ms` and the prefilter's keys/lookup split on `resolve timings`, and
`resolve corpus cached` (build time, rows, memory), so the next er-dev pass
accounts for every millisecond.

a_warm_detached_resolve_reads_no_file_and_standardizes_each_field_once now
asserts a warm call runs no `read_parquet`, and fails on the previous code.
a_cached_attached_resolve_matches_the_lake_resolve covers the attached path
and its rebuild on a new snapshot.

Refs #1429

Co-Authored-By: Claude Opus 5.5 <[email protected]>
athvin pushed a commit that referenced this pull request Dec 3, 2026
…key auth's connection (#1429)

On er-dev, #1515 brought standardize to 28 ms but the prefilter only fell from
138 to 123 ms. Serving the Parquet bytes from the file cache removed the EFS
reads, not the decode. Reading even one row decodes its whole row group, and a
probe's candidates span several of p3live's ~15 files.

Reproduced locally by writing the benchmark corpus in 15 files with the
probe's matches planted in five of them: the fetch went from about 2 to 21 ms.
Rewriting the cross-file OR as one per-file fetch with pushable filters changed
nothing.

On each corpus change the session now copies the whole corpus, with its
precomputed blocking keys, into a compressed in-memory database, and indexes
the keys. Each indexed lookup returns its candidates' rows directly; filtering
the copy by row id would scan every row group holding one. A warm call reads
no Parquet, on either path. At 780k records the copy holds 215 MiB, against
531 MiB as a temp table, and takes about 2.4 s to build once. The file-cache
settings from #1515 are removed, because they would only hold a second copy.
On the er-dev-shaped corpus, local, one thread: prefilter 25.2 -> 8.1 ms p50,
end to end 87/90 -> 69/73 ms p50/p95.

The handler spent ~42 ms outside the resolve stages, and opened two TLS
Postgres connections per request. The resolve route now opts in
(`ReuseKeyAuth`) to keeping the key extractor's connection and org row, so the
handler neither reconnects nor re-reads the org.

New log fields: `resolve request timings` (auth, lookup, blocking),
`setup_ms` and the prefilter's keys/lookup split on `resolve timings`, and
`resolve corpus cached` (build time, rows, memory), so the next er-dev pass
accounts for every millisecond.

a_warm_detached_resolve_reads_no_file_and_standardizes_each_field_once now
asserts a warm call runs no `read_parquet`, and fails on the previous code.
a_cached_attached_resolve_matches_the_lake_resolve covers the attached path
and its rebuild on a new snapshot.

Refs #1429

Co-Authored-By: Claude Opus 5.5 <[email protected]>
athvin added a commit that referenced this pull request Dec 3, 2026
…key auth's connection (#1429) (#1518)

On er-dev, #1515 brought standardize to 28 ms but the prefilter only fell from
138 to 123 ms. Serving the Parquet bytes from the file cache removed the EFS
reads, not the decode. Reading even one row decodes its whole row group, and a
probe's candidates span several of p3live's ~15 files.

Reproduced locally by writing the benchmark corpus in 15 files with the
probe's matches planted in five of them: the fetch went from about 2 to 21 ms.
Rewriting the cross-file OR as one per-file fetch with pushable filters changed
nothing.

On each corpus change the session now copies the whole corpus, with its
precomputed blocking keys, into a compressed in-memory database, and indexes
the keys. Each indexed lookup returns its candidates' rows directly; filtering
the copy by row id would scan every row group holding one. A warm call reads
no Parquet, on either path. At 780k records the copy holds 215 MiB, against
531 MiB as a temp table, and takes about 2.4 s to build once. The file-cache
settings from #1515 are removed, because they would only hold a second copy.
On the er-dev-shaped corpus, local, one thread: prefilter 25.2 -> 8.1 ms p50,
end to end 87/90 -> 69/73 ms p50/p95.

The handler spent ~42 ms outside the resolve stages, and opened two TLS
Postgres connections per request. The resolve route now opts in
(`ReuseKeyAuth`) to keeping the key extractor's connection and org row, so the
handler neither reconnects nor re-reads the org.

New log fields: `resolve request timings` (auth, lookup, blocking),
`setup_ms` and the prefilter's keys/lookup split on `resolve timings`, and
`resolve corpus cached` (build time, rows, memory), so the next er-dev pass
accounts for every millisecond.

a_warm_detached_resolve_reads_no_file_and_standardizes_each_field_once now
asserts a warm call runs no `read_parquet`, and fails on the previous code.
a_cached_attached_resolve_matches_the_lake_resolve covers the attached path
and its rebuild on a new snapshot.

Refs #1429

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 — df22364d Deployed Dec 2, 2026 by athvin via remove closed PR previews #205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-ticket deliberately not tied to a board ticket; exempts the pull request contract

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve latency: ~2.1 s p50 at 520k records because the corpus is materialised per request

2 participants