feat: Add BlockAllocator for 1D block memory management#8481
Merged
mvaligursky merged 2 commits intomainfrom Feb 26, 2026
Merged
feat: Add BlockAllocator for 1D block memory management#8481mvaligursky merged 2 commits intomainfrom
mvaligursky merged 2 commits intomainfrom
Conversation
General-purpose block allocator backed by a doubly-linked list with free-list threading. Supports first-fit allocation, O(1) free with automatic merging, grow-only expansion, incremental and full defragmentation, batch updateAllocation, and MemBlock object pooling. Includes comprehensive unit tests covering basic operations, merging, defrag, fragmentation metric, pool reuse, and stress tests with Uint32Array buffer integrity validation. Made-with: Cursor
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new internal 1D memory/block allocator to src/core and introduces a dedicated unit test suite validating allocation/free/merge behavior, growth, and defragmentation flows.
Changes:
- Introduces
BlockAllocator/MemBlockfor contiguous block allocation over a linear address space (with free-list + linked-list bookkeeping). - Implements grow-only capacity expansion, incremental defrag, full compaction, and a batch
updateAllocationAPI. - Adds a comprehensive Mocha/Chai test suite covering core behaviors and stress scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/core/block-allocator.js |
New allocator implementation with allocation/free, growth, defrag (incremental/full), and batch update API. |
test/core/block-allocator.test.mjs |
New test suite validating allocator invariants, merging, defrag behavior, pooling, and stress runs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix buffer resize bug in updateAllocation stress test (const -> let, assign resized buffer back) - Replace Math.random() with deterministic seeded PRNG (mulberry32) in all stress tests for reproducible results - Fix misleading comment in _defragIncremental phase 2 Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BlockAllocatorclass (src/core/block-allocator.js) for managing a 1D linear address space with contiguous block allocationsupdateAllocationAPIMemBlockhandles are pooled to minimize GC pressureUint32Arraybuffer integrity validation