Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance by removing 'self' field #163

Open
drekbour opened this issue Mar 11, 2019 · 1 comment
Open

Improve performance by removing 'self' field #163

drekbour opened this issue Mar 11, 2019 · 1 comment

Comments

@drekbour
Copy link
Contributor

I tested this using the JMH test cases return this; instead of the default return self; and saw very notable increase in performance (and decrease in heap allocation). I think the JVM doesn't know self will point to itself so reserves enough space for a second full builder object.

1 Use of self should be constrained to withGenerationGap.
2 Use of self vs casting should be compared (not done here)

PojobuilderPerformance.constructManually                                                 thrpt            243.662           ops/s
PojobuilderPerformance.constructViaBuilder_private                                       thrpt            145.929           ops/s
PojobuilderPerformance.constructViaBuilder_shared                                        thrpt            131.137           ops/s
PojobuilderPerformance.constructViaBuilder_threadlocal                                   thrpt            153.278           ops/s
PojobuilderPerformance.constructViaThisBuilder_private                                   thrpt            226.686           ops/s
PojobuilderPerformance.constructViaThisBuilder_shared                                    thrpt            141.562           ops/s
@drekbour
Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant