Skip to content

Conversation

@SyMind
Copy link
Member

@SyMind SyMind commented Oct 29, 2025

This PR introduces a ObjectPool system to optimize memory allocations by reusing Vec<usize> buffers, particularly for the WithIndices struct. The pool uses a BTreeMap to organize vectors by capacity and only pools vectors with capacity ≥ 64 elements to balance pooling benefits with overhead.

  • Adds ObjectPool and Pooled for efficient vector reuse
  • Threads memory_pool parameter through the StreamChunks trait and all implementations
  • Updates WithIndices to use pooled vectors instead of regular Vec<usize>

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 29, 2025

CodSpeed Performance Report

Merging #192 will improve performances by 20.83%

Comparing memory-pool (6ddd2b1) with main (98db0a7)

Summary

⚡ 2 improvements
✅ 9 untouched
⏩ 5 skipped1

Benchmarks breakdown

Benchmark BASE HEAD Change
complex_replace_source_map 51.6 ms 42.7 ms +20.83%
repetitive_react_components_map 2.6 ms 2.2 ms +15.68%

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@SyMind SyMind force-pushed the memory-pool branch 2 times, most recently from eac1e0d to 3a3faac Compare October 29, 2025 09:50
@SyMind SyMind force-pushed the memory-pool branch 5 times, most recently from 54f2f12 to 724819e Compare October 29, 2025 11:01
@SyMind SyMind marked this pull request as ready for review October 29, 2025 11:50
Copilot AI review requested due to automatic review settings October 29, 2025 11:50
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 introduces a MemoryPool system to optimize memory allocations by reusing Vec<usize> buffers, particularly for the WithIndices struct. The pool uses a BTreeMap to organize vectors by capacity and only pools vectors with capacity ≥ 64 elements to balance pooling benefits with overhead.

  • Adds MemoryPool and PooledUsizeVec for efficient vector reuse
  • Threads memory_pool parameter through the StreamChunks trait and all implementations
  • Updates WithIndices to use pooled vectors instead of regular Vec<usize>
  • Refactors MapOptions to manually implement PartialEq, Eq, and Hash traits

Reviewed Changes

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

Show a summary per file
File Description
src/memory_pool.rs Introduces new memory pool infrastructure with MemoryPool and PooledUsizeVec types
src/with_indices.rs Updates to use PooledUsizeVec instead of Vec<usize> with lifetime parameter changes
src/source.rs Adds manual trait implementations for MapOptions and threads memory_pool parameter through StreamChunks
src/helpers.rs Updates all streaming functions to accept and pass through memory_pool parameter
src/source_map_source.rs Threads memory_pool parameter and creates default pool where needed
src/replace_source.rs Updates to use memory_pool when creating WithIndices instances
src/raw_source.rs Adds memory_pool parameter to StreamChunks implementations (unused)
src/original_source.rs Adds memory_pool parameter to StreamChunks implementation (unused)
src/concat_source.rs Threads memory_pool parameter through nested stream_chunks calls
src/cached_source.rs Threads memory_pool parameter and updates tests
src/lib.rs Exports new MemoryPool type
tests/compat_source.rs Updates test implementation to match new StreamChunks signature

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

@SyMind SyMind changed the title perf: memory pool perf: object pool Oct 30, 2025
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