Open drekbour opened 5 years ago
Results of a Generation Gap builder using return (BookBuilder2)this;
instead of return self
are similarly enhanced:
PojobuilderPerformance.constructViaBuilder_private thrpt 143.334 ops/s
PojobuilderPerformance.constructViaBuilder_private:cycles:u thrpt 7328416.600 #/op
PojobuilderPerformance.constructViaBuilder_private:instructions:u thrpt 9539486.380 #/op
PojobuilderPerformance.constructViaBuilder_private:·gc.alloc.rate.norm thrpt 8005231.096 B/op
PojobuilderPerformance.constructViaThisBuilder_private thrpt 244.758 ops/s
PojobuilderPerformance.constructViaThisBuilder_private:cycles:u thrpt 4605288.336 #/op
PojobuilderPerformance.constructViaThisBuilder_private:instructions:u thrpt 6696290.695 #/op
PojobuilderPerformance.constructViaThisBuilder_private:·gc.alloc.rate.norm thrpt 3200551.912 B/op
In fact it reaches the same speed as manual construction which I cannot really explain but sure is interesting!
I tested this using the JMH test cases
return this;
instead of the defaultreturn self;
and saw very notable increase in performance (and decrease in heap allocation). I think the JVM doesn't knowself
will point to itself so reserves enough space for a second full builder object.1 Use of
self
should be constrained towithGenerationGap
. 2 Use ofself
vs casting should be compared (not done here)