Skip to content

Refactor offset-allocator to improve readability - #10

Draft
patowen wants to merge 1 commit into
pcwalton:mainfrom
patowen:refactor-for-rust-practices
Draft

Refactor offset-allocator to improve readability#10
patowen wants to merge 1 commit into
pcwalton:mainfrom
patowen:refactor-for-rust-practices

Conversation

@patowen

@patowen patowen commented Aug 3, 2026

Copy link
Copy Markdown

A few months ago, as part of my work on Hypermine, I was looking into this crate as something to potentially use to manage allocations in Vulkan. While evaluating this crate, I studied the code carefully to understand how it worked, and while doing so, I made some rather extensive refactors to make it easier for me to understand this code. Eventually, I was happy enough with the refactors that I was in favor of vendoring this dependency in Hypermine so that I could take advantage of these refactors.

However, it was suggested that I look into trying to contribute my refactor upstream. I was initially hesitant to do so because this crate was meant to be a port of a C++ package, which itself is considered an "early one weekend prototype", and it seemed like this crate is meant to be as faithful to that C++ package as well.

Regardless, I'm submitting this draft PR in case you are interested in seeing what I have so far, in case such a refactor is worthwhile to have upstream. If you are interested in such a PR, please let me know, and I can try to clean it up to make it easier to review (and ready for the library, as I still left a TODO in here).

This PR makes the following changes:

  • Add documentation to better explain how the allocator works
  • Use the slab crate for managing free node indexes (I may revert this part and use a different abstraction, as it's arguably more memory heavy)
  • Set up a newtype for SmallFloat
  • Create SmallFloatMap, which SmallFloat is used as an index for
  • Create BinsMap as a layer of abstraction for used_bins etc.
  • Set up a custom NodeIndexOption type to remove nonmax crate dependency

For further historical context on how these changes came to be, see these commit history of https://github.com/patowen/offset-allocator/commits/rewrite-wip/.

This commit makes the following changes:
* Add documentation to better explain how the allocator works
* Use the slab crate for managing free node indexes
* Set up a newtype for SmallFloat
* Create `SmallFloatMap`, which SmallFloat is used as an index for
* Create `BinsMap` as a layer of abstraction for `used_bins` etc.
* Set up a custom NodeIndexOption type to remove nonmax crate dependency
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.

1 participant