3 ms·
Something this doesn't mention is that for a given program written in both Java and say C++, the C++ version will have to perform much fewer allocations than th
by physguy1123 11y ago
Something this doesn't mention is that for a given program written in both Java and say C++, the C++ version will have to perform much fewer allocations than the Java one. Escape analysis can help with this but afaik it's not even a full replacement for stack allocation, not to mention the other scenarios where C++ doesn't allocate.
On the other side, this also doesn't bring up that any sort of concurrent data structure is much easier to write when using a GC, and the GC removes the need for expensive memory tracking. It doesn't necessarily make things faster, and libraries like Crossbeam and epoch management in general make things easier, but Crossbeam isn't fully featured, is Rust only, and still suffers from strange bugs.
A worthwhile side note is that when manually managing memory, non-malloc allocators can often be used if really needed that have far higher performance than both malloc/free and a GC.
- steveklabnik 11y agoWhat kind of strange bugs are you seeing with crossbeam? I haven't heard anyone say this yet, I'm curious :)
- physguy1123 11y agoThey've mostly been in the epoch manager itself - some were recently resolved, one has been pseudo-resolved by not freeing the respective memory, and I'm working on another right now. They're all edge cases, but they manifest as segfaults. Hopefully these can all be resolved soon though!
- steveklabnik 11y agoAh, interesting. thanks for elaborating, I will have to look into that. Crossbeam is one of my favorite libraries, but I haven't dug into the code as much as I should.
- qznc 11y agoInstead of Java, a comparison should use a language with value types (structs): C#, D, etc
- sixbrx 11y agoI like the C#/F# have value types, but they have the downside of not being able to do away with the default constructor for the type, meaning it's harder and less efficient to control type invariants (would have to guard validity in methods repeatedly instead of being able to gaurantee valid construction). For types for which a default/"0" value is a legal value they are good of course.
- qznc 11y agoI don't understand. What is the problem with default constructors?
- sixbrx 11y agoThe problem with the default constructors is just that for value types, you can't not have one. For plenty of kinds of things, there's no sensible default value that would make any sense, but your type must admit such a value anyway, there is no choice. Which means when you have a value of the type, you can't assume it's in a valid state. You have to put checking code somewhere, either in each method of the type, or in functions that receive the type as a parameter, in clients that create objects of the type, etc.
- physguy1123 11y agoThis article discussed Java, so I used Java. Also, C#'s value types are somewhat limited aren't they?
- qznc 11y agoI know too little C#. D is very flexible. It also allows to explicitly allocate (emplace) classes on the stack or in an array, for example. You can also wrap structs into a reference counting construct and use them as reference types.