kyren / gc-arena

Incremental garbage collection from safe Rust
Creative Commons Zero v1.0 Universal
438 stars 36 forks source link

fix remembered_size acc error #45

Closed dragazo closed 1 year ago

dragazo commented 1 year ago

Closes #44. Solves the overflow crash from accumulating remembered_size across collect cycles. I'm by no means an expert on this crate, so please check this thoroughly.

It seems like remembered_size was meant to be a running total through one collection cycle, but was not being reset to zero at the end of sweeping like allocation_debt was. To solve this, I just set it to zero along with allocation_debt and use the old value in the calculation of sleep for wakeup_total.

I've also included a regression test that makes sure that several similar values in Context all remain bounded. Unfortunately this required exposing a new public method in Arena for getting the value of remembered_size. Feel free to make changes if this can be avoided. I would have normally made it pub(crate), but the test module is not actually part of the crate it seems.

Aaron1011 commented 1 year ago

Thanks for the PR! This looks reasonable to me.