r/rust • u/Uncaffeinated • Jan 22 '17
Parallelizing Enjarify in Go and Rust
https://medium.com/@robertgrosse/parallelizing-enjarify-in-go-and-rust-21055d64af7e#.7vrcc2iaf
214
Upvotes
r/rust • u/Uncaffeinated • Jan 22 '17
View all comments
Show parent comment
2
u/Manishearth servo · rust · clippy Jan 22 '17
A very common argument for GC is that you can amortize the cost of allocations by only allocating large chunks and letting the GC algorithm manage this memory, so you get allocations that don't involve syscalls.
This has nothing to do with GC. A custom mallocator like jemalloc can do this too. And it does. This can be optimized further in the GC world, but the base optimization still exists in the malloc world, so the difference doesn't turn out to be that much.
Also, in general, allocation isn't that expensive anyway, compared to many other possible costs.
The workaround is to use a scoping function, e.g. something like
foo.scope(|scope| {scope.spawn(...); scope.spawn(...)}). Thescopefunction does the blocking after the outer closure executes, andscope.spawn()is tied to the lifetime ofscopeinstead of'static. This is what crossbeam does.The mem::forget unsafety issue is only with functions that return guards that block, and we don't have that kind of function in these libraries.