Skip to content

Makes the performance of the data fetcher better by caching the method lookups - #1013

Merged
bbakerman merged 3 commits into
graphql-java:masterfrom
bbakerman:1012-better-data-fetching-performance
May 6, 2018
Merged

bbakerman merged 3 commits into
graphql-java:masterfrom
bbakerman:1012-better-data-fetching-performance

Conversation

@bbakerman

Copy link
Copy Markdown
Member

see #1012 and a related PR #1011

rrva pushed a commit to rrva/hello-dataloader that referenced this pull request Apr 6, 2018
@rrva

rrva commented Apr 6, 2018

Copy link
Copy Markdown

Tried graphql-java from this PR and my benchmark project at rrva/hello-dataloader@ed80001

Much better response time behavior.

Did a quick profile to show what is left, but I am happy as is.

screen shot 2018-04-06 at 20 29 54

}

private String mkKey(Class clazz, String propertyName) {
return clazz.getCanonicalName() + "__" + propertyName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe base the cache key on something else than clazz.getCanonicalName() which seems to be slow due to being a native method?

https://bugs.openjdk.java.net/browse/JDK-5058117

consider if getName() is sufficient, since it seems to be cached.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

also, getCanonicalName seems to return null for anonymous inner classes:

package foo;
public class Foo {

    interface Bar {
        void baz();
    }

    public static void main(String[] args) {
        System.out.println("class name:"+Foo.class.getName());

        Bar b = new Bar() {
            @Override
            public void baz() { }
        };

        System.out.println("anon inner class name: "+ b.getClass().getName());
        System.out.println("anon inner class canonicalName: "+b.getClass().getCanonicalName());
    }

}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use a SimpleImmutableEntry as a stdlib included Pair/Tuple implementation for the key?

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.

Thanks - will change it to Class.getName()

private static final ConcurrentMap<String, Field> FIELD_CACHE = new ConcurrentHashMap<>();

/**
* PropertyDataFetcher caches the methods and fields that map from a class -> a property for runtime performance reasons.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

javadoc fails on using -> in a comment, change it to to

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.

fixed

@bbakerman
bbakerman merged commit 9a56e3f into graphql-java:master May 6, 2018
@andimarek andimarek added this to the 9.0 milestone May 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants