Re:Chromium project finds that 70% of security defects are m...
by pkolaczk on Sunday May 24, 2020 @01:54PM
(#23293220)
You can use GC to implement the persistent structure in C++/Rust just fine. But then you pay the GC cost for only that structure, not for all the other things.
Re:Chromium project finds that 70% of security defects are m...
by andrepd on Sunday May 24, 2020 @07:36AM
(#23290829)
Well yes, if you are comparing GC to refcounting then yes, gc wins.
Re:Chromium project finds that 70% of security defects are m...
by pkolaczk on Sunday May 24, 2020 @02:00PM
(#23293273)
I wouldn't be so sure. There is no easy answer. It typically wins in trivial benchmarks, where the total heap size is small. However once you have a big heap of other long lived stuff, there is a significant indirect cost caused by scanning the heap, memory barriers and evicting good data from caches. This cost is negligible only if your total heap size is much larger than the live memory set. Also modern manual memory allocators are not as slow as they used to be a few decades ago and they actually allocate in low tens of nanoseconds.
Re:Chromium project finds that 70% of security defects are m...
by _ph_ on Sunday May 24, 2020 @09:41AM
(#23291440)
If your problem demands many heap allocations, GC wins also vs. manual memory management. Heap allocation in a generational GC is as fast as stack allocation, you don't get fragmented heaps.
Re:Chromium project finds that 70% of security defects are m...
by pkolaczk on Sunday May 24, 2020 @02:01PM
(#23293284)
It is nowhere near stack allocation, please stop this nonsense. There was a paper claiming that, but the requirement was to set heap size 7x bigger than needed.
Stack is also very hot in cache. Memory that GC is handing allocations from is not.
I recently ported some of Cassandra code from Java to stack-only Rust and I got ~25x performance improvement, most from avoiding heap allocations and GC.
Re:Chromium project finds that 70% of security defects are m...
by dirtydroog on Sunday May 24, 2020 @10:26AM
(#23291744)
That depends on the allocator used. The default libc one works but isn't great performance-wise. It is possible to intercept calls to malloc/free by using LD_PRELOAD on Linux. That will allow you to use allocators such as jemalloc or tcmalloc instead.
Of course, repeatedly allocating and freeing is poor for performance. Cache/pre-allocate when you can. This goes for managed languages too.
You'll never actually see anyone tout the benefits of using GC for this, though, because the performance characteristics of persistent data structures are so horrendous compared to mutable ones, no one actually uses them in C++.