4 ms·
It is interesting to read the rules you came up with to limit memory usage, and then to think of the criticisms one gets in Java for limiting memory usage. In J
by whatisthiseven 6y ago
It is interesting to read the rules you came up with to limit memory usage, and then to think of the criticisms one gets in Java for limiting memory usage. In Java we try to limit new as much as possible to prevent the GC from pausing too much, or inconveniently, or for too long. And basically all the rules you say are what we also use in Java.
Except when you have these rules in Java, the ironic counter-point is "if you are doing this much memory control yourself, you should just use C or C++ or something".
I'll keep your comment in mind next time I see that rebuttal. Thank you.
- lmilcin 6y agoHaving almost 20 years of experience with Java... but are not following recent garbage collector developments. There is a bunch of misconceptions about Java. Java is actually very performant and memory allocation is generally cheaper than in C (except for inability to have good use of stack in Java). What's slow about Java is all the shit that has been implemented on top of it, but that's another story for another time. For example, allocation in Java is basically incrementing the pointer. And deallocation for most objects is basically forgetting the object exists. No, you don't want to "limit the use of new", that's wrong approach. What you want is to have objects that are either permanent or last very short amount of time. The worst types of objects are ones that have kind of intermediate lifetime ie if they are allowed to mature from eden. These cost a lot to collect. The objects that have very short lifetime are extremely cheap to collect. So if your function takes arguments, creates couple of intermediate objects and then never returns them (for example they were just necessary for inner working of the function) and your function does not call a lot of other heavy stuff, then it is very likely the cost of those temporary objects will be very low. Also, they tend to be allocated very close to each other and so pretty well cached.
- binwiederhier 6y agoThis was very insightful. Thank you.
- scns 6y agoWell that seems to align pretty well with Entities/Aggregates and ValueObjects in DDD.