Reputation: 138
I'm looking for resources to understand how Java datatypes are implemented internally, and how libraries like Fastutil and Eclipse Collections provide faster implementations of the same. I tired looking through the codebases on Github (https://github.com/vigna/fastutil and https://github.com/eclipse/eclipse-collections respectively), but I've only understood that code generators are used.
But what code generators are used? How are they used? Why does the generated code perform better? Why aren't these the default implementations in Java if they perform better?
I'm looking for any kind of resources/reading lists which cover this topic. Youtube and Google haven't helped much.
Thanks
Upvotes: 2
Views: 522
Reputation: 6706
Eclipse Collections uses StringTemplate to generate its primitive collections.
You can look in the Eclipse Collections repo in this directory to find the templates (under resources) and code for the code generator.
The code generation itself does not yield performance improvements. Using primitive collections can give you memory and performance improvements. Avoiding the hand-coding of collections for all primitive types is why code generation is used for Eclipse Collections.
There is an article here which explains some optimization strategies using Eclipse Collections.
JEP 218: Generics over Primitive Types is intended to address the performance issues of boxing in Java.
You should validate any expected performance gains by profiling or writing benchmarks for your application.
Note: I am a committer for Eclipse Collections.
Upvotes: 7