A more memory efficient directives container#4027
Merged
Conversation
bbakerman
commented
Jun 28, 2025
| * @return a map of all directives by directive name | ||
| */ | ||
| default Map<String, List<Directive>> getDirectivesByName() { | ||
| return ImmutableMap.copyOf(allDirectivesByName(getDirectives())); |
Member
Author
There was a problem hiding this comment.
This was terribly memory inefficient
bbakerman
commented
Jun 28, 2025
| * @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()); |
Member
Author
There was a problem hiding this comment.
This was terribly memory inefficient
bbakerman
commented
Jun 28, 2025
| * @return true if the AST node contains one or more directives by the specified name | ||
| */ | ||
| default boolean hasDirective(String directiveName) { | ||
| return !getDirectives(directiveName).isEmpty(); |
Member
Author
There was a problem hiding this comment.
This was terribly memory inefficient
bbakerman
commented
Jun 28, 2025
| @@ -34,20 +34,16 @@ public interface DirectivesContainer<T extends DirectivesContainer> extends Node | |||
| * | |||
Member
Author
There was a problem hiding this comment.
We no longer have default methods - but rather a memory efficient DirectivesHolder helper
bbakerman
commented
Jun 28, 2025
| NodeChildrenContainer newChildren = namedChildren.transform(builder -> builder.removeChild(childLocationToRemove.getName(), childLocationToRemove.getIndex())); | ||
| return node.withNewChildren(newChildren); | ||
| } | ||
|
|
Member
Author
There was a problem hiding this comment.
Our new helper thats immutable and more memory efficient
Contributor
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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