Others / shredder

Garbage collected smart pointers for Rust
MIT License
266 stars 9 forks source link

Create a HandleCache type #44

Open Others opened 4 years ago

Others commented 4 years ago

It'd be cool if on the hot path instead of writing:

for $BIG__LOOP {
    // do work
    let x = gc.get() // gets a handle every loop -- potentially expensive
    // operate on x

    // drop x/the handle
}

You could use a struct to cache the handles:

let cache = HandleCache::new();
for $BIG__LOOP {
    // do work
    let x = cache.get(gc) // only gets the handle once, then caches it
    // operate on x
}
// drop all the handles in the cache when it is dropped

We'd need to evaluate if this is ever potentially a footgun, but it would seem to provide more control over the whole collection process. (It also seems pretty straightforward to implement!)

Could be combined with #43 for a super fast hot path!!!