tikxml
tikxml copied to clipboard
Optimize generated Code for single attribute
If there is just one single attribute we don't have to allocate an extra HashMap
. In this case we can just use a simple if statement
It will be good idea to get rid of HashMap
and use switch
or if
(in single attribute case) in fromXml section if attribute has no @Path
annotation. It will speed up reading and save some memory.
For single attribute cases yes! for others I think we have to measure if switch
is really faster / slower than a hashmap. It also depends on Android runtime as it does some optimization on run time.
In theory switch on Strings is O(n)
whereas HashMap is O(1)
. However, compiler might transform switch to HashMap
on compile time anyway but this depends on compiler optimizations and jdk if I remember correctly. In general i think HashMap vs. switch is a micro optimizaion and we could tackle that later. Single Attributes is an optimization (not micro optimizaion) for sure and we gain much more from optimising this compared to HashMap
vs. switch
.
What do you think?
I have done some benchmarks with jmh on openjdk 1.8.0_152 linux-x64
with patches from intellij.
Turns out switch is actually cheaper than key lookup and calling method on interface, but I can upload jmh bechmark to github and you can see yourself.
would be interesting to run those benchmarks on android device (not sure if its possible though). Also related to #37 and #78
Not possible with jmh, but I can create new benchmark with Caliper.