Skip to content

perf(tables): evaluate one bar-family anchor per distinct breadth - #470

Open
xenokratos wants to merge 1 commit into
firecrawl:mainfrom
xenokratos:perf/bar-family-memoize
Open

perf(tables): evaluate one bar-family anchor per distinct breadth#470
xenokratos wants to merge 1 commit into
firecrawl:mainfrom
xenokratos:perf/bar-family-memoize

Conversation

@xenokratos

@xenokratos xenokratos commented Aug 29, 2026

Copy link
Copy Markdown

Fixes #469.

bar_family selects its family by breadth alone, and every later test reads only that family — so the closure's result is a pure function of the anchor's breadth. Rect-dense pages repeat the same widths hundreds of times, each recomputing an identical answer.

Evaluating one anchor per distinct breadth returns the same result: a repeat can only reproduce the earlier one, and that one was false or the any would already have stopped. Breadths compare by bit pattern, so near-equal widths are still evaluated separately.

On tests/fixtures/bits_pilani_feedback.pdf via pdf2md: 26.8s → 2.1s, markdown byte-identical (1,315,546 bytes). 1199 existing tests pass unchanged.


Summary by cubic

Memoizes bar_family evaluation by distinct breadth, fixing #469. Rect-dense page conversion drops from 26.8s to 2.1s with byte-identical output (1,315,546 bytes).

Repeats can only reproduce an earlier result since the closure reads only the breadth-selected family. Breadths compare by bit pattern, so near-equal widths are still evaluated separately. 1199 existing tests pass unchanged.

Written for commit 95a7b6d. Summary will update on new commits.

Review in cubic

has_chart_bar_signature's bar_family closure runs per anchor rect: it builds the
same-breadth family in O(n), then pairs that family against itself in O(family^2)
to reject grid rows. Over every anchor that is O(n * family^2), and on a
rect-dense page it dominates conversion - sample(1) attributes 9144 of 10047
samples, 91% of total time, to is_chart_bar_cluster.

The closure body reads only the family, and the family is selected by breadth
alone, so its result is a pure function of the anchor's breadth. Rect-dense pages
repeat the same widths hundreds of times, and each repeat recomputed an identical
answer. Evaluating one anchor per distinct breadth returns the same result: a
repeat can only reproduce the earlier one, and that one was false or the `any`
would already have stopped. Breadths are compared by bit pattern so near-equal
widths are still evaluated separately.

tests/fixtures/bits_pilani_feedback.pdf via pdf2md: 26.8s -> 2.1s, with
byte-identical markdown output (1315546 bytes). 1199 existing tests pass
unchanged.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Shadow auto-approve: would auto-approve. Memoizes bar-family evaluation by distinct breadth, skipping repeated anchors. Since the result is a pure function of breadth, behavior is preserved; rect-dense conversion drops from 26.8s to 2.1s with byte-identical output and 1199 tests passing.

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant