Skip to content

Criteria: compare each cell without copying it - #3365

Open
Morzilla wants to merge 1 commit into
storytold:mainfrom
Morzilla:perf/criteria-without-copies
Open

Morzilla wants to merge 1 commit into
storytold:mainfrom
Morzilla:perf/criteria-without-copies

Conversation

@Morzilla

@Morzilla Morzilla commented Nov 4, 2026 •

Copy link
Copy Markdown

For every cell it looked at, a criterion cloned the cell's value, copied its text, tokenized the pattern again and lowercased the text into a new vector. That happened even when the pattern had no wildcard, which is the usual case for COUNTIFS and friends.

The pattern is now tokenized once, when the criterion is parsed, and the cell is borrowed. A pattern without wildcards compares character by character with no copy. A pattern with wildcards takes the same path as before.

Measurements

Release builds, gridcraft-cli convert, on a generated workbook: 20,000 rows, two of the four columns formulas, and 3,000 COUNTIFS over whole columns with four criteria.

Build Seconds, two runs
main 49.3, 52.2
this PR 18.8, 19.0

Values: across 216 private workbooks (404,081 formula cells) every computed value matched main, and so did a private report with 244,621 formulas.

Testing

a_pattern_without_wildcards_matches_as_the_general_match_does compares the shortcut with the general matcher, including case, İ, ß, and ~ escapes.

fmt, assets, layers and wasm pass, and so does clippy on gridcraft-calc, gridcraft-functions and gridcraft-engine. Tests for those three crates: 1197 pass, 1 fails (engineering::tests::complex_numbers, a last-digit difference on my Windows machine in a test this PR doesn't touch). I ran these steps separately because cargo xtask ci doesn't pass on my machine, for reasons outside this change (see #3267).

This is independent of #2757, which adds an index for single-pair literal text criteria.

Summary by CodeRabbit

  • Improvements
    • Text criteria matching is more efficient for literal-only patterns and reuses prepared wildcard patterns. Wildcard matching behavior remains consistent, including for patterns that use the general matcher. These changes improve the efficiency of text filtering without altering the results users receive.

For every cell a criterion cloned the value, copied its text, tokenized the pattern
again and lowercased the text into a new vector, even with no wildcard in sight. The
pattern is now tokenized once, the cell is borrowed, and a pattern without wildcards
compares character by character with no copy. Results don't change: a test checks the
shortcut against the general match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Text criteria now store tokenized wildcard patterns. Matching borrows array values instead of cloning them. Literal-only wildcard patterns use direct character comparisons, while patterns with wildcards use the existing budget-limited matcher.

Changes: Criteria matching

Layer / File(s) Summary
Tokenized text matching
crates/functions/src/criteria.rs
Text criteria store pre-tokenized patterns. Matching borrows the first array value, uses stored tokens for text comparisons, and compares lowercased characters directly for literal-only patterns. A test compares this path with the general matcher.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related issues

  • storytold/gridcraft#2751 — The change reduces repeated text comparison work through stored tokens and direct comparisons.
  • storytold/gridcraft#775 — The change optimizes repeated criteria comparisons, which overlaps with the issue’s focus on scalable SUMIFS and COUNTIFS workloads.

Suggested reviewers: neilcawse

Merge Risk: Minimal · up to 9d084

The optimization has no identified merge-blocking risk, subject to normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Criteria: compare each cell without copying it" matches the main change in the changeset. The PR tokenizes criterion patterns once at parse time and borrows array values in Criterion::match…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Criteria: compare each cell without copying it" matches the main change in the changeset. The PR tokenizes criterion patterns once at parse time and borrows array values in Criterion::matches instead of cloning them. It also adds a literal-only comparison path for patterns without wildcards. The title names the criteria area and the no-copy comparison, which are the central points. It omits the tokenization detail, which is expected for a short title.

Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 632e4a1 and 9d08408.

Files selected for processing: 1
  • crates/functions/src/criteria.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

This branch has not been deployed

No deployments
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