shredder icon indicating copy to clipboard operation
shredder copied to clipboard

Create a HandleCache type

Open Others opened this issue 4 years ago • 0 comments

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!!!

Others avatar Aug 01 '20 06:08 Others