Skip to content

perf: avoid multiplying frontier result and claim rows - #87

Open
Afloat16 wants to merge 1 commit into
billion-token-one-task:masterfrom
Afloat16:perf/frontier-paper-counts-20261202-r2
Open

Afloat16 wants to merge 1 commit into
billion-token-one-task:masterfrom
Afloat16:perf/frontier-paper-counts-20261202-r2

Conversation

@Afloat16

@Afloat16 Afloat16 commented Dec 2, 2026

Copy link
Copy Markdown

Problem

The Frontier paper lookup joins every result with every claim for each linked paper, then uses distinct counts to recover the original totals. A paper with 400 results and 600 claims creates a 240,000-row intermediate solely to return three counters. This repeats whenever the evidence graph is assembled for a Frontier snapshot.

Changes

Count results, SOTA results, and verified claims in separate correlated subqueries using the existing paper_id indexes. Keep a single database statement and preserve the selected paper scope, missing-paper refusal, zero counts, and deterministic ordering.

Validation

  • 1 failed, 2 passed on base.
  • Real SQLite tables with the repository's relevant indexes return identical counters. A deterministic progress-handler measurement decreases from 5,425 to 6 callbacks per 1,000 virtual-machine instructions in the 400-result/600-claim fixture. The regression uses a generous instruction budget instead of a timing threshold.
  • Controls cover empty papers, papers with only results or claims, duplicate requested IDs, ordering, and missing references.
  • python -m pytest -q -s tests/test_frontier_paper_count_query.py tests/test_frontier_source.py tests/test_frontier_bootstrap_authority.py: 30 passed, 12 subtests passed.

The measured work reduction is from SQLite; no production PostgreSQL timing claim is made.

@cla-assistant

cla-assistant Bot commented Dec 2, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

1 participant