fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.36k stars 111 forks source link

Too large allocation because of doubling last allocation #152

Open stepancheg opened 2 years ago

stepancheg commented 2 years ago

Consider this scenario:

bumpalo will allocate 3M, because third allocation will create third chunk double the size of second chunk.

Instead bumpalo could do the following: if allocation size is larger than 1M, always allocate in the fresh chunk of size exact of allocation size, attach it to the tail of current chunk, and then continue allocating in the current chunk.

This will break this invariant of iter_allocated_chunks:

    /// The chunks are returned ordered by allocation time, with the most
    /// recently allocated chunk being returned first, and the least recently
    /// allocated chunk being returned last.