Skip to content

Optimize append-only leading-dimension resize performance - #92

Merged
TheGreatAlgo merged 3 commits into
mainfrom
faster-resize
Jul 30, 2026
Merged

Optimize append-only leading-dimension resize performance#92
TheGreatAlgo merged 3 commits into
mainfrom
faster-resize

Conversation

@eloramirez1356

@eloramirez1356 eloramirez1356 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces an optimized "fast path" for resizing Zarr arrays along their leading dimension when only appending new data, avoiding unnecessary shard snapshots and data movement. It adds a static method to detect when this optimization is safe, updates the resize logic to use it, and includes comprehensive tests to verify correct behavior and backward compatibility.

Optimized fast-path for leading-dimension resize:

  • Added _can_fast_resize_leading_dimension static method to ShardedZarrStore to detect when a resize is a strict append along the leading dimension and is safe to optimize.
  • Updated _resize_array_index to use the fast path when possible, skipping shard snapshots and preserving chunk and shard layout for appends.

Testing and validation:

  • Added new test file test_z16_fast_leading_resize.py with tests verifying:
    • The detection logic for fast-path eligibility.
    • That appending along the leading dimension skips shard snapshots and preserves data/chunks for both v1 and v2 manifests.
    • Integration with xarray’s append workflow.
    • That non-leading-dimension changes and shrinking still use the general (slower) resize logic.

Summary by CodeRabbit

  • Performance Improvements

    • Significantly faster resizing for row-major (C) arrays when only the leading dimension is append-only grown, avoiding unnecessary shard/metadata reprocessing.
  • Bug Fixes

    • Ensures correct resize behavior when changes don’t meet the fast-path rules (including non-leading shape changes and shrink), with proper manifest and shard updates.
  • Tests

    • Added new unit and async integration coverage for fast leading-dimension growth across manifest versions, including validation of appended data visibility after reopening and correct path selection.

@eloramirez1356 eloramirez1356 self-assigned this Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75b06879-daec-402c-aa2a-b3ba1414e4bc

📥 Commits

Reviewing files that changed from the base of the PR and between e4b3b43 and 24aff8e.

📒 Files selected for processing (1)
  • tests/test_z16_fast_leading_resize.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_z16_fast_leading_resize.py

Walkthrough

ShardedZarrStore fast-paths eligible row-major leading-dimension growth by updating array metadata in place without snapshotting shards. Tests cover v1, v2, xarray append behavior, strict eligibility, and fallback resizing.

Changes

Leading-dimension resize optimization

Layer / File(s) Summary
Fast resize implementation
py_hamt/sharded_zarr_store.py
Adds strict eligibility checks and updates ArrayIndex, legacy geometry, and root manifest state directly for eligible growth.
Resize behavior validation
tests/test_z16_fast_leading_resize.py
Tests shard preservation, multi-array manifest behavior, xarray appends, and snapshot-based fallback for other resize operations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ShardedZarrStore
  participant ArrayIndex
  participant RootManifest
  Caller->>ShardedZarrStore: resize_store(new_shape)
  ShardedZarrStore->>ArrayIndex: resize leading dimension in place
  ShardedZarrStore->>RootManifest: sync arrays and mark root dirty
  ShardedZarrStore-->>Caller: complete without shard snapshot
Loading

Possibly related PRs

Poem

I hopped through arrays, swift and bright,
Growing the first dimension just right.
Old shards stayed snug, new chunks came through,
Manifests kept every array in view.
Thump-thump, resize saved the day!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly matches the main change: a fast path for append-only leading-dimension resize optimization.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch faster-resize

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/test_z16_fast_leading_resize.py (1)

17-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add property-based coverage for resize geometry.

Use Hypothesis to generate C-order shapes, chunk shapes, shard sizes, and append lengths; retain the focused regression cases. This is required for tests in this repository.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_z16_fast_leading_resize.py` around lines 17 - 29, Extend
test_fast_leading_resize_requires_strict_append_only_growth with
Hypothesis-based generation of valid C-order array shapes, chunk shapes, shard
sizes, and append lengths, asserting the resize geometry contract for generated
inputs. Retain the existing focused regression assertions unchanged, and use the
repository’s established Hypothesis strategies and test conventions.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_z16_fast_leading_resize.py`:
- Around line 56-60: Apply Ruff’s required formatting in
tests/test_z16_fast_leading_resize.py at lines 56-60, 72-74, 129-134, 142-144,
and 190-195: reformat the AsyncMock expressions and chunk-write calls without
changing their behavior.
- Around line 230-233: Update the count_snapshot helper’s return annotation to
the precise shard-snapshot mapping type returned by _snapshot_shards_for_resize,
replacing the unparameterized dict while preserving its existing behavior.

---

Nitpick comments:
In `@tests/test_z16_fast_leading_resize.py`:
- Around line 17-29: Extend
test_fast_leading_resize_requires_strict_append_only_growth with
Hypothesis-based generation of valid C-order array shapes, chunk shapes, shard
sizes, and append lengths, asserting the resize geometry contract for generated
inputs. Retain the existing focused regression assertions unchanged, and use the
repository’s established Hypothesis strategies and test conventions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e692c8ff-d0a9-4638-b27f-923b193c906d

📥 Commits

Reviewing files that changed from the base of the PR and between 74ef73d and 8f8f13c.

📒 Files selected for processing (2)
  • py_hamt/sharded_zarr_store.py
  • tests/test_z16_fast_leading_resize.py

Comment thread tests/test_z16_fast_leading_resize.py
Comment thread tests/test_z16_fast_leading_resize.py Outdated

@da-code-reviewer da-code-reviewer 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.

Codex Automated Review

No high-confidence actionable issues found.
No inline issues were posted.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_z16_fast_leading_resize.py (1)

206-233: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Assert fallback data preservation, not only snapshot invocation.

This test proves that the general path is entered and the shape changes, but it would still pass if shard remapping dropped or corrupted existing chunks. Seed known data before resizing and reopen the store afterward to verify retained chunks and expected shrink behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_z16_fast_leading_resize.py` around lines 206 - 233, Strengthen
test_non_leading_change_and_shrink_use_general_resize by writing known chunk
data before resize, then reopening the store after resize and asserting retained
chunks still contain the expected values while data outside the new_shape is
removed. Keep the existing snapshot_calls and array_shape assertions to verify
both fallback-path selection and resize behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_z16_fast_leading_resize.py`:
- Line 124: Copy the manifest returned by
writable.array_indices["humidity"].to_manifest() before storing it in
humidity_manifest, ensuring its shard_cids data is independent of the store’s
mutable state for the later resize comparison.

---

Nitpick comments:
In `@tests/test_z16_fast_leading_resize.py`:
- Around line 206-233: Strengthen
test_non_leading_change_and_shrink_use_general_resize by writing known chunk
data before resize, then reopening the store after resize and asserting retained
chunks still contain the expected values while data outside the new_shape is
removed. Keep the existing snapshot_calls and array_shape assertions to verify
both fallback-path selection and resize behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f710f7b0-dda9-4bc1-b6aa-fb3dc44ad853

📥 Commits

Reviewing files that changed from the base of the PR and between 8f8f13c and e4b3b43.

📒 Files selected for processing (1)
  • tests/test_z16_fast_leading_resize.py

Comment thread tests/test_z16_fast_leading_resize.py

@da-code-reviewer da-code-reviewer 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.

Codex Automated Review

Found one actionable test reliability issue.
Posted 1 inline comment(s).

read_only=False,
root_cid=root_cid,
)
humidity_manifest = writable.array_indices["humidity"].to_manifest()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LOW
to_manifest() returns the live shard_cids list, so this baseline aliases the humidity index. An in-place mutation during resize would update both sides and let the array-locality assertion pass despite corruption. Copy the manifest, including shard_cids, before resizing.

@codecov-commenter

codecov-commenter commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (74ef73d) to head (24aff8e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #92   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines         3168      3180   +12     
=========================================
+ Hits          3168      3180   +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@da-code-reviewer da-code-reviewer 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.

Codex Automated Review

No high-confidence actionable issues found.
No inline issues were posted.

@TheGreatAlgo
TheGreatAlgo merged commit 97365e2 into main Jul 30, 2026
3 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.

3 participants