Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active October 23, 2022 11:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/4779c867e02f3de50bbd1cb01f82fb66 to your computer and use it in GitHub Desktop.
Save pervognsen/4779c867e02f3de50bbd1cb01f82fb66 to your computer and use it in GitHub Desktop.
// This is another take on the mark-compact collector from https://gist.github.com/pervognsen/7fe51bef8977cb249ac4c6f830f818a5
// To avoid having to do global compaction, our object indices will have two parts: a block index and a block offset.
// Within a block we have the same linear older-to-newer ordering by offset. But now blocks are allowed to have different ages.
// The block ages are defined by their position in a linked list: There's oldest_block and newest_block indices and then
// previous_block[block_index] for each block. This enables newest-to-oldest block iteration and the linked-list structure
// means that we can free an empty block by unlinking it. When a block is reused, it becomes the newest_block. Now, instead
// of only compacting within a block we will actually be coalescing across an age range of blocks. By doing so, we will usually
// be able to empty out entire blocks from the newer part of that age range, so they can be reused. This should have very similar
// performance characteristics to a generational collector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment