- Notifications
You must be signed in to change notification settings - Fork 1.1k
A more memory efficient directives container #4027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| * @return a map of all directives by directive name | ||
| */ | ||
| default Map<String, List<Directive>> getDirectivesByName() { | ||
| return ImmutableMap.copyOf(allDirectivesByName(getDirectives())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was terribly memory inefficient
| * @return the directives or empty list if there is not one with that name | ||
| */ | ||
| default List<Directive> getDirectives(String directiveName) { | ||
| return getDirectivesByName().getOrDefault(directiveName, emptyList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was terribly memory inefficient
| * @return true if the AST node contains one or more directives by the specified name | ||
| */ | ||
| default boolean hasDirective(String directiveName) { | ||
| return !getDirectives(directiveName).isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was terribly memory inefficient
| | ||
| /** | ||
| * This will return a Map of the all directives that are associated with a {@link graphql.language.Node}, including both repeatable and non repeatable directives. | ||
| * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer have default methods - but rather a memory efficient DirectivesHolder helper
| NodeChildrenContainer newChildren = namedChildren.transform(builder -> builder.removeChild(childLocationToRemove.getName(), childLocationToRemove.getIndex())); | ||
| return node.withNewChildren(newChildren); | ||
| } | ||
| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our new helper thats immutable and more memory efficient
Test Results 318 files - 632 318 suites - 632 2m 47s ⏱️ - 5m 38s Results for commit dcc6a93. ± Comparison against base commit aef8032. This pull request removes 480 and adds 146 tests. Note that renamed tests count towards both.This pull request skips 1 test. |
xuorig left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 perfect
When we wrote the
graphql.language.DirectivesContainerwe put default methods on it to save code in each language element that implemented itBut because interfaces cant have state, then it we doing a per "group by" etc... when each call was made.
This introduces a
DirectivesHolderhelper class (like we do in the runtime viagraphql.DirectivesUtil.DirectivesHolder) that holds the immutable state and helps each implementing class implement theDirectivesContainermethodsSo while there is more code in each, it more efficient than the
defaultinterface methods