Skip to content

perf(streams): bounded view for run() over an on-demand source (ITL-1464) - #560

Closed
eywalker wants to merge 5 commits into
mainfrom
eywalker/itl-1464-views
Closed

eywalker wants to merge 5 commits into
mainfrom
eywalker/itl-1464-views

Conversation

@eywalker

@eywalker eywalker commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Draft, track VIEWS of ITL-1464 (the issue stays open).

What this does

run() no longer needs the whole table for a SpiralDBTableSource, or for column selections, renames, add_tags, drop_nulls and filter over one: the source's batches go one at a time through each operator's own static_process, and a result of more than 50,000 rows or 64 MiB of values is not held (one that fits in the two 1,000-row windows always is). The design, with preview(n) and the job-node view (not implemented here), is docs/dev/specs/itl-1464-views.md.

Public changes, for the developer

  1. V2, flagged: the view of such a run above the limit (item 7) is bounded: view.table, as_table() and as_polars_df() raise BoundedViewError, naming stream.as_table(). They gave every row before.
  2. V3, flagged: on a bounded view, sort_by_tags() and head/tail beyond the first and last 1,000 rows raise it too.
  3. V8, flagged (design only): preview(n) would call user functions.
  4. V5: as_table() after such a large run of an operator stream reads the source and applies the operators again. A function pod never runs twice: a chain through one is not read in batches.
  5. V6: above the limit, the streams in the middle of a chain keep nothing. At or below it each keeps its result, as before.
  6. stream.head(n) after a large run shows the window (default columns, n up to 1,000); other column groups show not_computed. The notebook preview then shows the first ten rows of the result, sorted by tags, and says so.
  7. V4: the limit is 50,000 rows and 64 MiB of values, measured without the layout (no offsets, validity or chunks), so equal data always gives the same kind of view.
  8. New public error orcapod.errors.BoundedViewError.

Not batched, stated in the docs: polars_filter (V7), pick and index (their result types follow the values of a batch), tag_by, joins, group_by, batch, function pods, and user subclasses of a batched operator. No hash, identity, stored layout, stored byte or golden value changes; nothing in a job changes.

Measured (synthetic time series, about 2.2 million rows and 250 MiB; peak RSS of run())

Stream Before After Arrow pool peak before after Time before after
the source 10.8 GiB 1.24 GiB 9.3 GiB 0.07 GiB 8.9 s 10.4 s
map_data 10.8 GiB 1.40 GiB 9.3 GiB 0.25 GiB 8.8 s 10.5 s
drop_nulls 19.7 GiB 1.44 GiB 18.6 GiB 0.28 GiB 9.8 s 11.1 s
filter 15.1 GiB 1.45 GiB 14.1 GiB 0.29 GiB 9.2 s 10.2 s
drop_nulls, filter, map_data 20.1 GiB 1.55 GiB 18.6 GiB 0.39 GiB 10.2 s 9.9 s

Most of what remains should be the source's set of keys read (about 0.5 GiB in the diagnosis), which still grows with the table; not changed here.

Tests

tests/test_core/streams/test_bounded_run_view.py:

  • the batches give the whole (rows, order, types, nullability, metadata, tokens, record ids, row hashes, every column configuration), per operator and chained, three batch sizes, plain tags and data-tags;
  • the display of a small run equals that of a view of the whole; a bounded view's header, text and HTML equal the complete view's;
  • the limit for equal data however cut or already read; the refusals; head after a run and after the source moved;
  • errors: max_rows over the whole read, a late source error (also ahead of an operator's earlier error), an operator error; no view and nothing kept.

Run locally: those, the stream, source and operator tests, the ITL-1347 equivalence tests, doc samples, golden tests; ruff; whole-repository basedpyright (0 errors); golden --check (nothing moved).

Overlaps #558 in spiraldb_table_source.py (one hook here, two methods) and both add changelog.d/ITL-1464.md: whichever merges second joins the two texts. After #558, a bare source's run() can skip its tokens too.

Mentions ITL-1464.

ITL-1347 differential (both fixtures, spikes limited to 2,000, one and default Polars threads, cold/warm/load-only/held) against main 0d1e017, run on 2da7b22 (the staleness fix; the round 2 fix after it touches no job path): every branch-against-main comparison is equal, sync byte for byte and async as a multiset.
The harness reports async against sync as different in all 16 comparisons, on main too (both sides of this branch equal main's): not order, and no tag or data value. Two rows with equal function inputs are computed twice by async and once by sync, so the result table has a row more and the pipeline entries differ in __computed and __data_id; a side-effect node's rows carry a __computed column on async only.

Review findings and their tests

Finding Test
An intermediate above the limit keeps nothing, so a change beneath it was not seen: a stale window or a stale complete result was returned (blocker) test_no_result_is_shown_or_read_after_an_upstream_change (source refreshed, intermediate cleared, operator modified; window and retained; intermediate run or read before or after; depth 1 and 3), test_every_step_over_a_shared_intermediate_sees_a_change
An empty source was scanned twice test_a_read_of_no_rows_scans_once, test_a_pass_through_run_scans_once
StreamView's docstring claimed every row docstring
Round 2: a cached preview walked upstream states exponentially in the depth of a chain test_a_cached_preview_asks_each_stream_once (chains and diamonds, depth 4 to 40, kept and window)
Round 2: 50,000 wide rows were held test_a_wide_result_is_bounded_by_its_values, test_value_bytes_do_not_depend_on_the_layout, test_a_result_that_fits_in_the_windows_is_kept_however_wide

🤖 Generated with Claude Code

eywalker and others added 2 commits November 25, 2026 01:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…464)

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

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.30640% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/orcapod/core/streams/view.py 96.89% 5 Missing ⚠️
src/orcapod/core/operators/static_output_pod.py 97.67% 2 Missing ⚠️
src/orcapod/core/streams/base.py 95.45% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/orcapod/core/operators/add_tags.py 100.00% <100.00%> (ø)
src/orcapod/core/operators/column_selection.py 99.35% <100.00%> (+0.01%) ⬆️
src/orcapod/core/operators/drop_nulls.py 99.01% <100.00%> (+<0.01%) ⬆️
src/orcapod/core/operators/filter.py 100.00% <100.00%> (ø)
src/orcapod/core/operators/mappers.py 99.35% <100.00%> (+<0.01%) ⬆️
src/orcapod/core/sources/spiraldb_table_source.py 98.14% <100.00%> (+0.34%) ⬆️
src/orcapod/errors.py 95.94% <100.00%> (+0.01%) ⬆️
src/orcapod/core/streams/base.py 96.37% <95.45%> (-0.30%) ⬇️
src/orcapod/core/operators/static_output_pod.py 96.18% <97.67%> (+0.03%) ⬆️
src/orcapod/core/streams/view.py 94.59% <96.89%> (+1.14%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…an an empty source once (ITL-1464)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… by its values (ITL-1464)

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

eywalker commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing as part of the ITL-1464 draft group. The async-route work continues as ITL-1347 stage 5 (ITL-1845). The SpiralDB read work landed in #687 and #679, and continues in #683.

Posted by a Claude Code agent on behalf of @eywalker.

@eywalker eywalker closed this Dec 2, 2026
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