Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize resizing scratch allocator #70

Open
NotAPenguin0 opened this issue Aug 14, 2023 · 2 comments
Open

Optimize resizing scratch allocator #70

NotAPenguin0 opened this issue Aug 14, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@NotAPenguin0
Copy link
Owner

  • When allocating a new block, make it twice as large as the current largest block
  • When resetting the frame, use the largest block as the new buffer
@NotAPenguin0 NotAPenguin0 added the enhancement New feature or request label Aug 14, 2023
@jedjoud10
Copy link
Contributor

Currently the scratch allocator "merges" all blocks when it gets reset and create a mega-block with a size equal to the sum of all current blocks like this

self.buffers.iter().map(|buf| buf.size()).sum()

Would we allow users to switch between this and the proposed method or should we just implement the proposed method as new default behavior?

Imo I think we should since it would simplify the reset function (since we wouldn't need to allocate a new buffer, just re-use the largest existing one) but it could cause issues when something like this happens (for example):

  • Allocate 1024 (creates block with size of 1048 or chunk_size)
  • Allocate 1000 (creates block with size of 1048 (for alignment maybe?) or chunk_size)
  • Reset (uses block of 1024 as new buffer)
  • Does 1. and 2. again, which would cause the second allocation to actually need to actually allocate a new buffer for it (unless buffers do not get deallocated, in which case idk why even bother)

@NotAPenguin0
Copy link
Owner Author

In your example, the second block allocated would be 2096 bytes large and that would be the one used next frame (allocate the new block with 2x the size of the previous largest block)

jedjoud10 added a commit to jedjoud10/phobos-rs that referenced this issue Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants