Skip to content

perf(resolve): a cached session per dataset and a blocking prefilter, ~5x faster at 520k (#1429) - #1476

Merged
athvin merged 1 commit into
mainfrom
perf/1429-resolve-latency
Nov 30, 2026
Merged

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

Conversation

@athvin

@athvin athvin commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Closes #1429

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

What

  • A cached session per dataset (er-server). resolve_blocking keeps one session and its er_cli::ResolveCache per dataset lake env (RESOLVE_SESSIONS).
    • The key is the whole env, so a publish changes it.
    • A failed resolve drops its session.
    • Calls serialize per dataset.
    • This applies only over a postgres: catalog. A DuckDB-file catalog's process lock would shut the writer out (seen in pg_launch_proof), so those lakes still open per request.
  • er_cli::resolve_record_cached and ResolveCache.
    • The frozen TF tables are cached by CSV path, model version and TF snapshot.
    • The corpus's record_key plus the blocking rules' columns are cached in memory by lake snapshot.
    • Every rule, in both orientations, selects the corpus records that can pair with the probe. Only those are read and scored. Array-exploding rules skip the prefilter.
  • A one-source probe. The probe is standardized with only its own source declared.
  • Unchanged signature. resolve_record keeps its signature by passing a fresh cache. std_corpus moves above resolve_record's doc comment, which Account datasets: match-preview and blocking-estimate read only int_std_records #1368 had separated from its function.
  • Tests and docs.
    • The ignored benchmark resolve_latency_at_scale (er-cli).
    • Unit tests for the alias rewrite, rule-column extraction and catalog cacheability.
    • A new section in the er-server-control-plane reference with the before and after numbers.

Why

At about 520k records, resolve took p50 2092 ms and p95 2199 ms on er-dev (#1365). Every call opened a lake session, read the TF CSV, and copied the whole standardized corpus through materialize_concat to block a single probe against it.

Proof

resolve_latency_at_scale at 519,984 synthetic records with distinct blocking keys, 20 timed calls after 5 warm-ups (loaded machine, ±50 ms):

Path p50 p95
before (full corpus per call) 1414 ms 1639 ms
prefilter only 1029 ms 1204 ms
this PR, cached session 295 ms 340 ms
  • Same answers: the test asserts every cached call matches the uncached first call (decision plus candidate keys and probabilities).
  • Existing tests: the er-cli resolve tests (7) and acct_ tests (12) pass, and pg_launch_proof (HTTP resolve, three calls) passes.
  • make check: exit 0.

The ticket's target is measured on er-dev after deploy, where the per-request lake attach and the object-store corpus scan also go away. The numbers will go in the ledger.

Risk & rollback

  • Memory: a cached session holds a narrow in-memory key table per dataset (record_key plus about 6 blocking columns; tens of MB at 520k) and the TF tables. At most 32 envs are kept before the map clears.
  • Concurrency: resolves serialize per dataset.
  • Staleness: the key cache is keyed by lake snapshot, so a new run's records are seen on the next call.
  • Rollback: git revert <merge-sha>.

Post-merge ledger

Closed by: unclosed

  • 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:
  • images built, or correctly never ran because nothing that goes into
    an image changed:
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion:
  • 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:
  • the board card reached Done through the automation rather than by
    hand, and the issue closed:
  • follow-ups are open for everything deferred here — numbers:
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned:

Specific to this change

  • er-dev resolve latency at p3live (about 520k) after deploy: p50/p95 over 55 calls, against the 300 ms p95 target:

🤖 Generated with Claude Code

… ~5x faster at 520k (#1429)

POST …/resolve took p50 2092 ms / p95 2199 ms at ~520k standardized records on
er-dev (#1365). Every call opened a lake session, read the TF CSV, and copied
the whole corpus through materialize_concat to block one probe against it.

- er-server: resolve_blocking keeps one session and its er_cli::ResolveCache
  per dataset lake env (RESOLVE_SESSIONS). A publish changes the key; a failed
  resolve drops its session; calls serialize per dataset. This is only for a
  postgres: catalog; a DuckDB-file catalog's process lock would shut the writer
  out, so those lakes still open per request.
- er_cli::resolve_record_cached and ResolveCache: the frozen TF tables are
  cached by CSV path, model version and TF snapshot. The corpus's record_key
  plus the blocking rules' columns are cached by lake snapshot. Every rule in
  both orientations selects the records that can pair with the probe, and only
  those are read and scored. Blocking already limited the pairs, and the TF is
  frozen, so the answer is unchanged. Array-exploding rules skip the prefilter.
- The probe is standardized with only its own source declared.
- resolve_record keeps its signature (a fresh cache). std_corpus moves above
  resolve_record's doc, which #1368 had separated from the function.

Measured by the new ignored resolve_latency_at_scale test at 519,984 synthetic
records with distinct blocking keys: p50 1414 to 295 ms, p95 1639 to 340 ms.
Every cached call matches the uncached first call. Before and after are in the
er-server-control-plane reference. er-dev, where the per-request lake attach and
object-store reads also go away, is measured after deploy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@athvin
athvin merged commit 5f1e3bb into main Nov 30, 2026
43 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 30, 2026 05:20 — with GitHub Actions Inactive
athvin added a commit that referenced this pull request Nov 30, 2026
…e scan for one-off calls (#1429) (#1482)

#1476 made no difference on er-dev, and its p95 got worse (p50 about 2.2 s, p95
3.9 to 7.8 s). Provisioning writes ER_LAKE_CATALOG as ducklake:postgres:..., and
resolve_session_cacheable accepted only postgres:, so er-dev never kept a
session. Every call then took the one-off path, which in #1476 scanned the S3
corpus twice: once to build the key table and again to fetch candidates.

- resolve_session_cacheable accepts ducklake:postgres: as well as postgres:. A
  unit test pins the provisioned form.
- ResolveCache::persistent() marks a cache that outlives the call; the server
  uses it. A one-off cache (resolve_record) filters the lake corpus directly in
  one scan, as before #1476's key table.

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 — daf227c8 Deployed Nov 30, 2026 by athvin via remove closed PR previews #180
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