Skip to content

Conversation

@mgyoo86
Copy link
Collaborator

@mgyoo86 mgyoo86 commented Dec 11, 2025

Summary

  • Add reset!(pool) for state-only reset (preserves allocated vectors)
  • Make rewind!(pool) safe when called without matching checkpoint!
  • Clean up internal API and reorganize state.jl

New

  • reset!(pool): State-only reset (n_active=0, stacks to sentinel, vectors preserved)
  • reset!(pool, Type): Type-specific reset
  • reset!(pool, Type...): Multi-type reset

Modified

  • rewind!(pool): At depth=1 (no checkpoint), delegates to reset! instead of error/undefined behavior
  • rewind!(pool, Type): At depth=1, delegates to reset!(TypedPool)
  • rewind!(pool, Type...): At depth=1, delegates to reset! for each typed pool

API Comparison

Function n_active Checkpoint stacks Vectors
rewind! Restore to checkpoint Pop Preserved
reset! Set to 0 Clear to sentinel Preserved
empty! Set to 0 Clear to sentinel Cleared

Use Case: Unmanaged acquire cleanup

function inner!(pool)
    v = acquire!(pool, Float64, 100)
    # No rewind! called
end

for _ in 1:1000
    inner!(pool)  # n_active grows
end

# Option 1: Use reset! (new API)
reset!(pool)  # Clear n_active, keep vectors for reuse

# Option 2: Use rewind! (now safe at global scope)
rewind!(pool)  # Safe! Delegates to reset! when no checkpoint exists

Safety Improvements

  • All rewind! variants at depth=1 (no checkpoint) now delegate to reset!
    • rewind!(pool), rewind!(pool, Type), rewind!(pool, Type...)
  • Multiple rewind! calls without checkpoint are safe
  • reset! followed by rewind! is safe
  • Normal checkpoint!/rewind! cycle works after reset!
  • All rewind operations use orphan-safe _rewind_typed_pool! with depth tracking

Internal Cleanup

  • Remove redundant TypedPool public overloads (checkpoint!(tp), rewind!(tp))
  • Consolidate internal helpers: _checkpoint_typed_pool!, _rewind_typed_pool!
  • Reorganize state.jl into clear sections: checkpoint!, rewind!, empty!, reset!

Changes

  • src/state.jl: Add reset!, add depth=1 guard to rewind!, reorganize structure
  • test/test_state.jl: Add 20+ tests for reset! and safe rewind behavior

Add reset!(pool) that clears all n_active counters and checkpoint stacks
to sentinel state while preserving allocated vectors for reuse.

Unlike empty! which releases all memory, reset! allows continued use of
pre-allocated storage - useful when functions acquire without proper
checkpoint/rewind management.
Cover 10 test cases including:
- Basic n_active reset to zero
- Vector preservation after reset
- Checkpoint stack restoration to sentinel
- Fallback types (others dict) handling
- nothing compatibility
- Pool usability after reset
- A/B scenario (unmanaged acquires then reset)
- reset! vs empty! comparison
- TypedPool direct reset
When rewind! is called at depth=1 (no pending checkpoints), it now
safely delegates to reset! instead of breaking.

This enables:
- Safe rewind! without matching checkpoint
- Safe rewind! after reset!
- Multiple consecutive rewind! calls
- A/B scenario cleanup with just rewind!
@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (1e6cd56) to head (4305ac3).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master       #8      +/-   ##
==========================================
+ Coverage   96.52%   96.68%   +0.16%     
==========================================
  Files           7        7              
  Lines         575      603      +28     
==========================================
+ Hits          555      583      +28     
  Misses         20       20              

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new reset! function for state-only cleanup that preserves allocated storage, and improves safety of rewind! when called without a matching checkpoint. The changes enable cleanup of unmanaged acquires while avoiding memory reallocation costs.

Key Changes:

  • New reset! function that clears state (n_active, checkpoint stacks) while preserving all allocated storage (vectors, views, caches)
  • Safety guard in rewind!(pool::AdaptiveArrayPool) that delegates to reset! when called at depth=1 (no checkpoint)
  • Comprehensive test coverage with 14 new tests for reset! and 4 tests for safe rewind! behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/AdaptiveArrayPools.jl Exports the new reset! function
src/state.jl Implements reset! for TypedPool and AdaptiveArrayPool; adds depth=1 safety guard to rewind!
test/test_state.jl Adds comprehensive tests for reset! behavior and safe rewind! at depth=1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add reset!(pool, Type) and reset!(pool, Type...) for API consistency
- Add depth=1 safety guard to rewind!(pool, Type) and rewind!(pool, Type...)
- Add tests for type-specific reset! and safe typed rewind! behavior
- Remove redundant TypedPool public overloads (checkpoint!/rewind!)
- All rewind variants now use _rewind_typed_pool! with orphan cleanup
- Reorganize state.jl into sections: checkpoint!, rewind!, empty!, reset!
- Update tests to use internal helpers (_checkpoint_typed_pool!, _rewind_typed_pool!)
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- checkpoint!(pool, Type): explicitly return nothing
- rewind!(pool, Type): explicitly return nothing
- reset!(pool, Type): return pool (not TypedPool)
- reset!(pool, Type...): return pool (not nothing)
@mgyoo86 mgyoo86 merged commit 18fea63 into master Dec 11, 2025
8 checks passed
@mgyoo86 mgyoo86 deleted the feat/reset branch December 11, 2025 05:34
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