33 points · by ingve · 6y ago · 56 comments
Java is too extreme with GC, not all languages are like that. In .NET it's only moderately hard to avoid GC when you want to. It has value types, real stack, and other relevant features. Here's an example of non-trivial code written in that style for performance reasons: https://github.com/Const-me/Vrmac/tree/master/VrmacVideo
The considerations can be very complex though, e.g. what's the effort required for reaching this performance profile? is it consistent across all the types of project? etc.etc.
It is often easier to get decent performance in tiny projects or micro-benchmarks, simply because you can spend so much more time on optimization vs all other tasks. That's probably why I often see Java benchmarks claiming close-to-C performance (only ~2x slower) levels, but I fail to see it in real big applications.
2 - Those languages offer C++ like features for memory management if one bothers to actually learn to use them
3 - Java is also getting them via projects Panama and Valhalla
So it is more a matter to actually bother to learn the tools one has at their disposition.
2 - Not really. The fact they allow to allocate/deallocate manually is not enough. Dealing with non-GCed memory in Java or C# is much more error-prone and less ergonomic than even in C++. E.g. no automatic reference counting nor RAII.
3 - It is 5 years in development now and as far as the specs goes value types will be limited to immutable objects only, so it is inefficient by design and it solves only half of the problem. Similarly high hopes were associated with escape analysis which turned out to be totally ineffective.
I've ran into situations when displaying text on the screen was lagging - and that in several different programs, on various (modern) computers. Not saying GC was a problem there, but I guess this has something to do with the generally accepted culture of "only 2% of programs need high performance".
https://ruudvanasseldonk.com/2015/10/06/neither-necessary-no...
Ownership model seems hard for people to internalize, but once learned feels very natural, leads to programs that are better structured and frees programmer from "manually managing resources".
Other than Python's `with` and alikes, wrapping in a closure, `defer`/`scope` (Go/D), what else is there? What am I missing? None of these work if the lifetime of a resource is not a simple "this scope".
But it's a good advice. For some reason people tend to forget that copying stuff is super cheap, and most lifetime issues can be entirely avoided with a `.clone()`.
I remember years ago coming across a highly optimised md5 calculation function in a legacy codebase that I inherited. Much care have been put into writing it, with comments highlighting how many clock cycles on an Athlon processor were required to run it. This was clever stuff, but the firm wasn't using Athlon processors, and hadn't for years. A quick comparison with boost showed that boost was faster (on the processors of the time), so it got chopped out.
The more you use one tech (especially out of the usual zone) the more you learn. And maybe you learn to avoid that language.
Also I like being able to come back and pick up small tools in my 'main' languages without rewriting them. So for me it's java for GUIs or highly dynamic runtime-y stuff (introspection, code gen, AOP) or 'throwable' stuff, and Ada for 'serious real-time must run 2 years without crash' stuff.
Too many times I end up maintaining python scripts that have overgrown the 'script' phase and are full fledged business-critical tools and... It's then often too late to back off.
All there is just bunch of subjective experiences in specific circumstances.