Repository navigation
Conversation
Kotlin data classes generate getXXX methods for Boolean properties instead of isXXX. This causes NoSuchMethodException to be thrown on each access to a Boolean field, which is expensive performance-wise due to the fillInStackTrace() method called when the exception is created. Avoid this by caching the method prefix (get or is).
|
Also opened #1012 for the other performance area that could be improved in PropertyDataFetcher |
| try { | ||
| return getPropertyViaGetterUsingPrefix(object, "is", methodFinder); | ||
| } catch (NoSuchMethodException e) { | ||
| booleanMethodPrefixCache.put(className, "get"); |
There was a problem hiding this comment.
will it be enough? My guess propertyName should be used in the cache.
|
Thanks very much for this PR. I would love to see this take further and cache more than just booleans but the other accessors as well. That said caching is tricky. I property fetcher for the property "foo" just says given and object Bar how do I read the foo field. We have to make sure that any caching is aware that an object presented to the property fetcher might be different each time. Hmmm I need to consider this a little longer.. |
|
I had a look into this more. I think if we are going to cache for performance we want to do that for all methods of class -> property name not just boolean ones. So I created another PR #1013 I thank you for this PR but am going to close it and run with the other one |
Kotlin data classes generate getXXX methods for Boolean properties
instead of isXXX. This causes
NoSuchMethodExceptionto be thrownon each access to a Boolean field, which is expensive performance-wise
due to the
fillInStackTrace()method called when the exception iscreated. Avoid this by caching the method prefix (get or is).
This flame graph shows the cost of throwing NoSuchMethodException often:
The graph above is reproduced using the code at https://github.com/rrva/hello-dataloader which contains load test scripts as well to highlight the problem.