e.g. consider a particle simulation with “class Particle { Vector pos; Vector vel; }”. If Vector is a pointer type then the GC will have to scan every Particle. But if Vector is a value type, then GC can avoid looking inside Particles entirely. Now imagine you have 1M particles…
-
-
Show this thread
-
Of course in Java you would often optimize this as “class Particle { float pX, pY, pZ, vX, vY, vZ; }”. But then you’re in the bad situation of having to choose between having nice methods on vectors and performance. Value types let you have both.
Show this thread
End of conversation
New conversation -
-
-
It’s not really true that a generational GC will just eat those allocations up since that “eating” has cost. Also value types don’t go “on the stack”. The benefit of value types is some combination of the values being register allocated, less GC pressure, and less ptr chasing.
-
The JVM and most other VMs use escape analysis (really: SROA) to promote non-value types to registers already.
- 2 more replies
New conversation -
-
-
One of the interesting things about moving to more value types is that you start to see your GC retaining and moving nearly 100% of data through gen1/gen2... and all of a sudden you start implementing "pretenuring" or "large / long-lived object allocation" directives.
-
We saw this a lot as a fallout of aggressive monomorphization combined with inlining & contraction, as those reduced a lot of the small object allocations that were really only around to allow potential polymorphic usage & generic iteration constructs.
- 1 more reply
New conversation -
-
-
This is one of the reasons I hate Java so much. It constantly forces you to choose between good abstractions with horrible performance, or terrible abstractions with better (but still bad) performance
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Yup, practical limitations on heap size in garbage collected runtimes are often really due to object count rather than byte size of data.
-
You can get around that by having accessor interfaces into arrays of data, but value types can hopefully add more memory layout guarantees that lets the runtime optimize such accesses and conversions from bytes to other primitive types.
End of conversation
New conversation -
-
-
but that implies that typed array libraries get you all the perf benefit of value types
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.