Avoid assertion messages in free_list_allocator in release builds.#7
Avoid assertion messages in free_list_allocator in release builds.#7Craig-Macomber merged 4 commits intoCraig-Macomber:mainfrom
Conversation
Change some `assert`s to `debug_assert`s, for smaller code size in release builds. And, avoid doing an integer divison in `round_up` and `multiple_below`, by taking advantage of the fact that the denominator is always a power of two. These functions are often inlined, in which case the optimizer can see the powers of two and do this optimization itself, however this isn't always done when optimizing for size.
lol_alloc/src/free_list_allocator.rs
Outdated
| // From https://github.com/wackywendell/basicalloc/blob/0ad35d6308f70996f5a29b75381917f4cbfd9aef/src/allocators.rs | ||
| // Round up value to the nearest multiple of increment |
There was a problem hiding this comment.
It would be good to document the new requirement on increment here.
And while you are at it, a doc comment on multiple_below for it as well would be good.
|
Somehow I forgot about debug_assert when I wrote this, and that absolutely is what I intended. Great fix. This rest is probably good, but could use a bit more docs as I noted with inline comments. Thanks for the change: If you don't get around to addressing my feedback on this PR, I'll do so myself later when I have more time as this is a great improvement which I do want to get merged. |
And add a unit test for `round_up`.
|
I've now added comments and a |
|
I checked (using test.sh) and this seems to save 1 byte in my test case. I suspect apps with more dynamic allocation calls will benefit more, but its nice to confirm its a win even in my test. |
|
Published in 0.4.1 |
Change some
asserts todebug_asserts, for smaller code size in release builds.And, avoid doing an integer divison in
round_upandmultiple_below, by taking advantage of the fact that the denominator is always a power of two. These functions are often inlined, in which case the optimizer can see the powers of two and do this optimization itself, however this isn't always done when optimizing for size.