Skip to content

perf(resolve): serve candidates from an in-memory corpus copy, reuse key auth's connection (#1429) - #1518

Merged
athvin merged 1 commit into
mainfrom
perf/1429-resolve-prefilter
Dec 3, 2026
Merged

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

Conversation

@athvin

@athvin athvin commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Closes #1429

The dev-only release of this change met #1429's gate on er-dev before merge: in-cluster wall p95 116.7 / 120.6 ms at 779,861 records (server request p95 112 ms, prefilter p50 15 ms). The owner approved the production rollout afterwards. Measurement

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

What

  • Candidates come from an in-memory corpus copy.
  • One Postgres connection per resolve request. The resolve route opts in with a ReuseKeyAuth layer. The key extractor then keeps its connection and org row, and the handler stops reconnecting and re-reading the org by name. Other routes are unchanged.
  • Diagnostics for the next er-dev pass:
    • resolve request timings: auth_ms, lookup_ms, blocking_ms.
    • resolve timings gains setup_ms, prefilter_keys_ms and prefilter_lookup_ms.
    • resolve corpus cached: build time, rows and memory, logged once per corpus change.

Why

On er-dev at a1dd29d5, standardize fell to 28 ms, but the prefilter only went from 138 to 123 ms p50, now 63% of the resolve. Pod: 1 CPU on an m6a.large, DuckDB on one thread, corpus on EFS (efs.csi.aws.com at /srv/er).

Root cause: Parquet row-group decode, not I/O. Reading even one row decodes its whole row group. p3live's candidates sit in several of its ~15 data files, so every call decoded several files. The file cache served the bytes from memory but couldn't skip the decode.

The local benchmark had missed it because its corpus was one file. I wrote it in 15 files with the probe's matches in five, and the fetch went from about 2 to 21 ms. Rewriting the cross-file OR as per-file fetches with pushable filters changed nothing, which rules out filter pushdown.

The ~42 ms outside the resolve stages included two TLS Postgres connections per request, one in key auth and one in the handler, plus a duplicate org read.

Proof

  • Guard: a_warm_detached_resolve_reads_no_file_and_standardizes_each_field_once now also asserts that a warm call runs no read_parquet (from DuckDB's query log). It fails on a1dd29d5: "a warm resolve decoded Parquet".
  • Attached path: a_cached_attached_resolve_matches_the_lake_resolve covers a persistent cache over an attached lake. It must equal the uncached resolve, and after a write that makes a new snapshot, the late record must be a candidate at once.
  • Server: pg_launch_proof runs against a local Postgres 16 over the key-auth reuse path, with a new unknown-dataset 404 case: pass.
  • Tests: DEDUPE_E2E_DUCKLAKE=1 cargo test -p er-cli --test main resolve: 8 passed (the benchmark is ignored by design).
  • Gate: make check: exit 0 (fmt, clippy, doc, entities-check, skills-check and the other gates, then cargo test --workspace: 1279 passed, 0 failed).

Risk & rollback

  • Memory: about 215 MiB per resolved dataset at 780k records (the uncompressed alternative was 531 MiB).
  • Cold call: it now copies every column, so expect longer than the 2.9 s it takes today on er-dev.
  • Auth connection: held to the end of a resolve request rather than dropped after auth.
  • Rollback: git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:cf299f4a-bafd-4f62-a459-2f495e05c5f2 on Mac · 2026-12-03T01:40: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: f4c401d3. rust 47010872494, frontend 47010872442, infra 47010872302, devcontainer 47010872357 and images 47010872193 all success.
  • images built, or correctly never ran because nothing that goes into
    an image changed: images 47010872193 built er-api:f4c401d3 (sha256:1e55c99e…). er-web was skipped, with no frontend change.
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: deploy 47011447130 (deploying f4c401d3…), dev and prod jobs success. Dev: ci/er-api selects green, running sha256:1e55c99e…. That process emitted this PR's new line, resolve corpus cached (build_ms 5760, 779,861 rows, 334.6 MiB), and resolve request timings on a real resolve. Prod's process-level proof is a separate item below.
  • 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 on dev and prod. This deploy also healed the two refused frontend deploys (c7e8bc3, f7ed273) that my dev-only candidate push caused; fix in fix(deploy): reuse the newest image built from the deployed commit's history #1552. drift has been red on schedule since at least Nov 29, before this change. The kind nightly hasn't run since the merge; it doesn't exercise resolve.
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: Resolve latency: ~2.1 s p50 at 520k records because the corpus is materialised per request #1429 closed by this merge (closing reference).
  • follow-ups are open for everything deferred here — numbers: fix(deploy): reuse the newest image built from the deployed commit's history #1552 (the digest-reuse fix exposed by the dev-only release). No other deferral.
  • 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 measured results on Resolve latency: ~2.1 s p50 at 520k records because the corpus is materialised per request #1429; session memory notes on the deploy dispatch/reuse traps.

Specific to this change

  • er-dev 55-call pass on p3live: server request p50/p95, the resolve timings medians (against prefilter 123 / 185 and resolve total 195 / 287), and the new prefilter_lookup_ms. On main's dev deploy (f4c401d3), in-cluster: wall p50/p95 110.9/123.3 and 105.8/122.7 ms over 2×55 calls, 779,861 records, snapshot 29533. Server request p50/p95 108/121. resolve timings: total 88/100, prefilter 16.1/19.8, prefilter_lookup_ms p50 11.0, standardize 27.9. The candidate run before merge (dev-only, 93e43da5) gave in-cluster p95 116.7/120.6. #1429

  • The ~45 ms outside resolve: read auth_ms, lookup_ms and blocking_ms from resolve request timings, plus setup_ms and load_ms. If auth_ms is still the bulk, a pooled connection for key auth is the next lever. Request p50 108 vs resolve p50 88: the gap fell from ~45 to ~20 ms. auth_ms p50/p95 12.6/15.8 is now most of it; lookup 0.8, load 5.1, setup 0.45. A pooled key-auth connection would save ~10 ms, and isn't needed for the gate.

  • resolve corpus cached on er-dev: build_ms, rows and memory, and the pod's memory after the pass (it was 729 MiB before). build_ms 5760, rows 779,861, memory 334.6 MiB (dev-only candidate: 5541 ms, same size). After two warm passes the fresh green pod's er-server uses 395 MiB.

  • Prod serving proof: blocked — this session has no read access to er-prod (the er-mgmt SSO role has no EKS access entry there, and er-prod-admin uses the expired er-platform session). The deploy-prod job succeeded and https://dupezero.com/api/healthz returns {"ready":true,"upstream":"ok"}, but no line from prod's running process has been read. Whoever holds er-prod access: confirm app/er-api serves sha256:1e55c99e….

Context — plan, discoveries, measurements, files

Discoveries

  • Live logs (read-only, web-api-blue). Over 119 warm calls the prefilter ranged 88–226 ms (p50 123). One cold call, so the session persisted. load_ms was about 4 ms. request − total − load was 42.6 / 50.7 ms (p50 / p95).
  • Pod spec (read-only). 1 CPU, 3 Gi memory. /srv/er is EFS through the CSI driver with default mount options. DuckDB's spill directory is an emptyDir. The node is an m6a.large, spot. Single-core speed is about 2.4× below local, judging by standardize (28.3 against 11.7 ms).
  • Row-id filters don't help. Filtering the in-memory copy by rowid in (…) was slower (40 ms): with candidates spread out, it scans most row groups. Only returning rows from the index lookups themselves avoids that.
  • Extension and the spec deriver. The OpenAPI deriver refused Extension<…> as an unknown extractor. It now ignores it, like State and Principal: server-side state, never client input.

Measurements

resolve_latency_at_scale, 779,728 records written in 15 files with the probe's matches in five (9 candidates), one thread. p50 / p95 in ms:

Phase Before (a1dd29d5) After
standardize 12.0 / 12.5 12.1 / 13.2
prefilter 25.2 / 25.9 8.1 / 9.2
candidate fetch 21.1 / 21.7 6.0 / 6.8
predict 39.1 / 41.3 38.7 / 40.0
end-to-end call 87 / 90 69 / 73

The corpus copy holds 215.4 MiB with COMPRESS, against 531.5 MiB as a temp table, whose lookups are 3.1 ms instead of 6.0 ms. Build time is about 2.4 s.

Files

  • rust/crates/er-cli/src/lib.rs: the corpus copy, indexed fetch, prefilter timings and setup_ms. Removes the file-cache settings and the per-call file fetch.
  • rust/crates/er-cli/tests/lake_e2e.rs: the benchmark's 15-file shape, the no-read_parquet guard, and the attached-path test.
  • rust/crates/er-server/src/lib.rs: ReuseKeyAuth and KeyAuth, the resolve handler's reuse, and resolve request timings.
  • rust/crates/er-server/tests/pg_launch_proof.rs: the unknown-dataset 404 case.
  • rust/crates/er-api-spec/src/operations/requests.rs: ignore Extension.
  • .claude/skills/er-server-control-plane/references/handlers-and-state.md: the online-resolve reference.

🤖 Generated with Claude Code

@athvin athvin added the no-ticket deliberately not tied to a board ticket; exempts the pull request contract label Dec 2, 2026
@athvin
athvin force-pushed the perf/1429-resolve-prefilter branch from 325ca78 to e7fd758 Compare December 3, 2026 00:01
athvin pushed a commit that referenced this pull request Dec 3, 2026
A resolver candidate (#1518, for #1429) has to be measured on er-dev
before it reaches production. Only a merge or a manual dispatch could
deploy it, and both ran the dev and prod jobs, so a dev-only release
needed a by-hand blue/green outside CI.

workflow_dispatch gains an `environment` input (both | dev | prod,
default both). Each job skips when the input targets only the other
environment. Merges are unchanged: they arrive through `images` and
deploy both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
athvin added a commit that referenced this pull request Dec 3, 2026
* ci(deploy): let a manual deploy target dev or prod alone

A resolver candidate (#1518, for #1429) has to be measured on er-dev
before it reaches production. Only a merge or a manual dispatch could
deploy it, and both ran the dev and prod jobs, so a dev-only release
needed a by-hand blue/green outside CI.

workflow_dispatch gains an `environment` input (both | dev | prod,
default both). Each job skips when the input targets only the other
environment. Merges are unchanged: they arrive through `images` and
deploy both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci(deploy): regenerate the required-checks reference for the new job conditions

The skills gate generates the deploy jobs' conditions into the
ci-and-supply-chain reference. The dispatch `environment` input changed
both, so the committed table was stale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@athvin
athvin force-pushed the perf/1429-resolve-prefilter branch from e7fd758 to 93e43da Compare December 3, 2026 00:42
@athvin

athvin commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

Heads-up from a parallel session (2026-12-03 ~01:00Z): the manual dev deploy of this branch at 00:45 (deploy run 47005705531, DEPLOY_SHA 93e43da5) left its er-api image as the newest digest in ECR. main's deploys reuse the newest er-api when a commit has no Rust change, and the guard in deploy-resolve-digests.sh now refuses them because Rust differs between 93e43da5 and main (run 47007375189, for c7e8bc3c: "Refusing to deploy rather than reporting success on a stale image"). Dev and prod are therefore not taking main's merges for now; prod is unaffected and still serving 3b3a94f0.

I have NOT rebuilt images for main, because the deploy that follows would overwrite this branch on dev while you may be measuring it. When the dev test is done: gh workflow run images.yml -f ref=<current main sha> builds a fresh er-api from main, and its deploy restores dev and prod to main.

@athvin athvin removed the no-ticket deliberately not tied to a board ticket; exempts the pull request contract label 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

athvin commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

Resolved: this PR's merge (f4c401d3) built er-api from main, and main's deploys go through again — 4d1109ff deployed to dev and prod (run 47013310720). Nothing left to do from the note above.

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.

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

2 participants