Skip to content

perf: materialize sections once in resolve_batch and trim before resolution - #110

Merged
SkyeAv merged 1 commit into
mainfrom
tcode-optimizations
Aug 21, 2026
Merged

perf: materialize sections once in resolve_batch and trim before resolution#110
SkyeAv merged 1 commit into
mainfrom
tcode-optimizations

Conversation

@SkyeAv

@SkyeAv SkyeAv commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

resolve_batch re-executed the entire upstream lazy plan — source scan, encoding/regex ops, NLP normalization — once per resolved node column: distinct(...).collect() per column, join_matches' collect per column, and log_unmatched's anti-join collect with --log. A section resolving subject + object + two qualifiers ran that pipeline ~5× (~9× with logging).

Changes

  • resolve_batch (fullmap.py) collects the frame exactly once; per-column term extraction, unmatched logging, and join-backs all run against the in-memory frame. Output rows are unchanged.
  • join_matches keeps its LazyFrame-in/LazyFrame-out contract over a new eager core (_join_matches_eager) that resolve_batch calls directly.
  • trim moves from the finalize ops (_provenance_ops) to just before resolve_batch (_node_ops), so the materialized frame and every downstream join drop the spent raw column_<n> columns early. All readers of those columns run earlier, so this is safe; prune_to_class skips them regardless via its not any(accepts) branch.
  • trim's PHASE_OF entry is removed so progress falls back to transform instead of flashing finalize before resolve.

No reordering of filters was needed — every row-reducing op already runs before resolution (pinned by tests/test_lib.py).

Testing

  • uv run pytest -q → 928 passed; the 1 failure + 1 collection error are pre-existing environment issues (this venv lacks the [qc] extra — both fail on the clean tree too).
  • ruff check, ruff format --check, pyright → clean.
  • Synthetic before/after benchmark (50k rows, 4 resolved columns, --log): resolve phase 0.14s → 0.08s (~1.75×), identical output rows. Real tables with heavier encoding chains should gain more, since the eliminated cost is per-column re-execution of the whole upstream plan.

Changelog entry added under Unreleased → Performance.

…lution

resolve_batch re-executed the entire upstream lazy plan (source scan,
encoding/regex ops, NLP normalization) once per resolved node column:
distinct().collect() per column, join_matches' collect per column, and
log_unmatched's anti-join collect with --log. A section resolving
subject + object + two qualifiers ran that pipeline ~5x (~9x logging).

### Implementation
- resolve_batch collects the frame exactly once; term extraction,
  unmatched logging, and per-column join-backs run on the in-memory frame.
- join_matches keeps its LazyFrame contract over a new eager core
  (_join_matches_eager) that resolve_batch calls directly.
- trim moves from the finalize ops to just before resolve_batch, so the
  materialized frame and downstream joins drop the spent raw column_<n>
  columns early; its phase label falls back to transform.

### Testing
- uv run pytest -q: 928 passed (1 failure + 1 collection error are
  pre-existing: this venv lacks the [qc] extra; both fail on the clean
  tree too).
- ruff check / ruff format --check / pyright: clean.
- Synthetic 50k-row, 4-column benchmark: resolve phase 0.14s -> 0.08s
  (~1.75x), identical output rows.
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b4a86dd1-3b22-4683-99af-3400fd07bea7


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

Comment @coderabbitai help to get the list of available commands.

@SkyeAv
SkyeAv merged commit 2b429b5 into main Aug 21, 2026
5 checks passed
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