Skip to content

Faster Property fetching with derived classes - #2019

Merged
bbakerman merged 2 commits into
masterfrom
faster-property-fetcher
Sep 8, 2020
Merged

bbakerman merged 2 commits into
masterfrom
faster-property-fetcher

Conversation

@bbakerman

Copy link
Copy Markdown
Member

I found a bug on the VERY important PropertyDataFetcher where methods on derived classes are not cached properly.

This leads to things running slower than they are intended.

We also invoke too much code when we DO have a cached method and this simplifies that, doing way less work on POJO method invocation

I created a benchmark for this - on my Mac Pro -

Baseline:
Bencnchmark                                                            Mode  Cnt        Score       Error  Units
PropertyFetcherBenchMark.benchMarkThroughputDirectClassHierarchy    thrpt   15  1085518.250 ± 19039.649  ops/s
PropertyFetcherBenchMark.benchMarkThroughputInDirectClassHierarchy  thrpt   15    48904.567 ±  2916.355  ops/s

After Inprovements
Benchmark                                                            Mode  Cnt        Score       Error  Units
PropertyFetcherBenchMark.benchMarkThroughputDirectClassHierarchy    thrpt   15  1459934.015 ± 29543.790  ops/s
PropertyFetcherBenchMark.benchMarkThroughputInDirectClassHierarchy  thrpt   15  1441122.199 ± 54806.438  ops/s

@bbakerman
bbakerman requested a review from andimarek September 5, 2020 11:03
@bbakerman bbakerman added this to the 16.0 milestone Sep 5, 2020
//
if (isNegativelyCached(cacheKey)) {
return null;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I flipped the negative cache down in the order because I think the "positive case" is more likely - that is for any property X on a source object we have a method to get it.

So now if we DONT have a cached method we will try to see if its negatively cached (could not be found before) and the do the full search for it

This is a minor improvement because it avoids a map lookup in the case where we have methods, which I beleive is the best case to chase first

MethodFinder methodFinder = (aClass, methodName) -> cachedMethod;
try {
return getPropertyViaGetterMethod(object, propertyName, graphQLType, methodFinder, environment);
return invokeMethod(object, environment, cachedMethod.method, cachedMethod.takesDataFetcherEnvironmentAsOnlyArgument);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now do LESS work to invoke the property get

String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
try {
Method method = methodFinder.apply(object.getClass(), getterName);
if (takesDataFetcherEnvironmentAsOnlyArgument(method)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously we always did this method call - now we cache this knowledge just like the method itself


then:
result == "bar"
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests all pass and I tweaked this one to ensure out caching works for Foo extends Bar case

@dfa1

dfa1 commented Sep 5, 2020

Copy link
Copy Markdown
Contributor

Would be great to get this in the next release/backport 🚀

@bbakerman

Copy link
Copy Markdown
Member Author

Would be great to get this in the next release/backport 🚀

It will go out in 16.0 - we only maintain one LTS release and thats 14.x

I suspect this can be backported - lets try and see

@bbakerman bbakerman added the needs to be backported a bugfix that still needs to be backported label Sep 7, 2020
@bhabegger

Copy link
Copy Markdown

Could we have a pre-release or snapshot version of this where we could test it's impacts ?

@andimarek

Copy link
Copy Markdown
Member

@bhabegger every development build from master is available via maven central.

@bbakerman
bbakerman merged commit 30e680b into master Sep 8, 2020
@bbakerman

Copy link
Copy Markdown
Member Author

This will result in a development build now that its merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs to be backported a bugfix that still needs to be backported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants