Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Disagree about garbage collected runtimes.

A lot of widely used software is written in C or C++ and uses malloc/free extensively (C++ new/delete is mostly a wrapper around it). This results in memory layout worse than an equivalent managed heap would be. Happens because the memory allocated on C heap is immovable, while garbage collectors may move data around to defragment the heap.



Actually...https://arxiv.org/pdf/1902.04738.pdf

On a more serious note, most c programs I see don't do very much of that, preferring to allocate fixed-size buffers on the stack. Additionally, most GC'd languages that aren't java have crappy GCs, and those GC'd languages that are java lack value types. This harms spatial locality quite a bit, and compaction can't fully compensate for that.

They are working on adding value types to the jvm, though; it will be very interesting to see how performance changes. (I expect not very much in practice—those projects for which performance was important were already using whatever tricks they needed to—but perhaps it will improve the ergonomics of performant java.)


> preferring to allocate fixed-size buffers on the stack

When working set is measured in megabytes, it fits in L3 cache of modern CPUs. Memory layout is not too important for these programs.

> most GC'd languages that aren't java have crappy GCs

C# is good too. It also has value types, native memory spans, SIMD intrinsics, and stackalloc.


Don't forget that good cache locality also can cause data being pulled into cache that the prefetcher did know nothing about.

I can create you a shitty linked list that fits perfectly in L3, but still has terrible cold cache performance because each individual cacheline has to be pulled in one by one.


Indeed, there're edge cases. Still, how many people using linked lists on the stack?


Doesn't D have value types via structs since by default they're stack allocated and copied? Though I'm not sure how well it's GC performs when you do allocate on the heap.


Oh yes, plenty of GCed languages have value types. But they're not java and their GCs are garbage. D's is particularly bad, probably 30 years out of date.


Data-oriented designs like ECS implementations often use generational indices, which can support relocation and defragmentation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: