-
Notifications
You must be signed in to change notification settings - Fork 34
why not use a map for class->adapter mapping #180
Comments
There are a couple problems with using a map rather than the current implementation
For the other cases, I will look into using |
There was a bug in my original benchmark that resulted in unnecessary object creation. I have updated it to remove the unnecessary object creation, see below. The benchmark does not show a significant performance difference between the two implementations, and if anything shows that using the Let me know if you find a problem in the benchmark or have other data that shows that using the map is faster. Updated `HashMap` vs `if/else` benchmarkclass Scratch {
} Given that there are no performance benefits to switching to a map, the main differences that I see are:
There is some difficulty in adding in an abstraction to determine whether a type adapter is stateless and can be statically held in a map, so I'm going to hold off trying to implement a static map until it's clear that the benefits outweigh using the if/else. |
@anthonycr given that this is used by Android apps, I believe there was a cost involved in loading of classes which would be incurred during a cold boot scenario. We should check for those before we make this change. cc : @anirudhramanan who would have more info on the benchmarks we ran for this. |
As @yasirmhd mentioned, the cold boot time increased significantly when we tried the map implementation for the same. (shooted up to 4.2 sec from 2.4 seconds) Reasons being:
These optimisations helped us bring down the cold boot time significantly. |
Issue Summary
why not use a map for class->adapter mapping. currently is using a complicated package-> index-> subFactory-> if-else logic, which is neither efficient nor easy to understand.
Expected Behavior
just generate a map<Class, TypeAdapter> which will be extremely easy to debug and read
The text was updated successfully, but these errors were encountered: