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…
-
-
Prikaži ovu nit
-
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.
Prikaži ovu nit
Kraj razgovora
Novi razgovor -
-
-
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.
- Još 2 druga odgovora
Novi razgovor -
-
-
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.
- Još 1 odgovor
Novi razgovor -
-
-
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
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
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.
Kraj razgovora
Novi razgovor -
-
-
but that implies that typed array libraries get you all the perf benefit of value types
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.