News for hackers. Stuff that matters.
Re:Rust: Dropping heavy things in another thread can make yo... by Reelin on Saturday May 30, 2020 @01:54PM (#23363117)
> The only way to drop an extensively nested structure like this any faster than traversing it would be an arena allocator, and forgetting about the entire arena.

Isn't that incompatible with RAII though?

Re:Rust: Dropping heavy things in another thread can make yo... by arcticbull on Saturday May 30, 2020 @01:59PM (#23363162)
You can handle this in Rust pretty neatly with lifetimes. There's a bunch of crates that do this. [1]

[1] https://crates.io/crates/typed-arena

Re:Rust: Dropping heavy things in another thread can make yo... by Reelin on Saturday May 30, 2020 @02:22PM (#23363352)
That's a neat library but as far as I can tell it doesn't avoid any traversal or cleanup code. It appears to delay the cleanup so it all happens at once. That's certainly useful, but if you have RAII the traversal still has to happen at some point.
Re:Rust: Dropping heavy things in another thread can make yo... by winstonewert on Saturday May 30, 2020 @03:55PM (#23364089)
It avoids it if your type has no-op drop implementation. So if you use typed-arena for objects which don't own resources, they all get dropped in one massive deallocation and don't have to be traversed.

EDIT: and then I noticed that you mentioned RAII... Right, if the object own some sort of resources that doesn't apply.

Re:Rust: Dropping heavy things in another thread can make yo... by Reelin on Saturday May 30, 2020 @04:49PM (#23364576)
No worries. And to clarify, in context the point is that traversal fundamentally can't be avoided in the case of RAII. This defeats (what I see as) the primary use case of an arena allocator - deallocating an arbitrarily large chunk of contiguous memory in O(1) time regardless of object count.

Of course this is all somewhat tangential to the original topic of generational GCs, where the RAII idiom also has significant negative impacts. The performance characteristics would otherwise be O(n) based on the live set and thus similar to an arena allocator in terms of the ability to dispose of an arbitrarily large number of objects efficiently.

Re:Rust: Dropping heavy things in another thread can make yo... by winstonewert on Saturday May 30, 2020 @05:39PM (#23365005)
I'm not sure its fair to say it defeats that use case. It only defeats that use case if you need RAII. Furthermore, in my experience, an arena is most useful when you allocate lots of small objects which is the least likely to case to need RAII.
Re:Rust: Dropping heavy things in another thread can make yo... by Reelin on Saturday May 30, 2020 @08:24PM (#23366078)
I think we're violently agreeing?

RAII is the only use case I was speaking of there. Way back up thread the original post I responded to was talking about arena allocators in comparison to a generational GC and finalizers. The point is that a generational GC doesn't handle finalizers well, but neither does an arena allocator!

Re:Rust: Dropping heavy things in another thread can make yo... by winstonewert on Saturday May 30, 2020 @09:08PM (#23366329)
Yes. We are violently agreeing
Re:Rust: Dropping heavy things in another thread can make yo... by all-fakes on Saturday May 30, 2020 @07:55PM (#23365942)
Yes. Some libraries, like typed-arena (and Rust's built-in Vec), will traverse the structure and call the drop implementations, and others, like bumpalo, will just leak the resources.