Skip to content

[perf] Grow partition metadata row capacity geometrically - #229

Merged
0oshowero0 merged 2 commits into
Ascend:mainfrom
christian-muertz:perf/geometric-partition-row-growth
Nov 26, 2026
Merged

0oshowero0 merged 2 commits into
Ascend:mainfrom
christian-muertz:perf/geometric-partition-row-growth

Conversation

@christian-muertz

Copy link
Copy Markdown
Contributor

The Python controller grows each partition's production tensor and every consumer's status vector to the exact row count requested. Appending one row at a time repeatedly copies the whole partition. This change doubles row capacity when it fills and still satisfies a larger request in one allocation. It trades spare rows for fewer copies. A fetch with an empty field list considers only active rows, so spare capacity cannot appear in the result.

Starting with one row and requesting capacities 1 through 1,024 in order gave the following counts with one registered consumer.

Current main This change
Resizes 1,023 10
Existing rows copied per status tensor 523,776 1,023
Final capacity 1,024 1,024

All 59 tests in tests/test_controller_data_partitions.py pass. The new regression test fails on main and covers reuse of a spare row, preservation of consumed state, and visibility of spare rows on fetch.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T09:07:22.587498Z c357bbf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@0oshowero0 0oshowero0 changed the title Grow partition metadata row capacity geometrically [perf] Grow partition metadata row capacity geometrically Nov 26, 2026
@0oshowero0

Copy link
Copy Markdown
Collaborator

Thanks for the PR @christian-muertz! Geometric row growth is a good point for incremental inserts.

I pushed a small follow-up commit (bd5f741) to address two edge cases exposed by spare capacity:

  1. Ensure capacity on mode="insert" (transfer_queue/controller.py)
    TransferQueueController.get_metadata(mode="insert") added newly allocated rows to partition.global_indexes without calling ensure_samples_capacity. With geometric doubling leaving spare rows, a single insert batch could straddle allocated_samples_num—making an empty-field fetch([]) expose only the prefix within current capacity, until a subsequent read-only get_consumption_status expanded the tensor and revealed the rest (and similarly causing out-of-bounds failures for get_production_status / mark_clearing / clear_meta before update_production_status). Calling ensure_samples_capacity(max(batch_global_indexes) + 1) on insert keeps production_status and consumption_status aligned with all active rows immediately.

  2. Scan from active rows instead of allocated_samples_num (transfer_queue/controller.py)
    Spare rows are zero-initialized in consumption_status, so building row_mask over allocated_samples_num caused scan_data_status to include all spare rows (and slice all columns via production_status[row_mask][:, col_mask]) on every fetch, regressing fetch latency right after crossing a doubling boundary or on sparse partitions. scan_data_status now looks up consumption_status directly (avoiding the redundant sort inside get_consumption_status(..., mask=False)), filters sorted active indexes (self.global_indexes) by unconsumed status, and indexes only the requested columns (production_status[unconsumed[:, None], field_indices]). This also unifies the empty-field_names path without a separate post-filter.

  3. Regression test (tests/test_controller.py)
    Added TestTransferQueueController.test_controller_empty_field_fetch_after_insert covering the insert -> fetch([]) sequence before and after read-only get_consumption_status / get_production_status queries.

Verified locally with pytest -q tests/test_controller_data_partitions.py tests/test_controller.py (91 passed) and pre-commit checks.

@0oshowero0
0oshowero0 merged commit b75c37b into Ascend:main Nov 26, 2026
16 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.

2 participants