Skip to content
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

Improve ENF isConditional #3241

Merged
merged 6 commits into from Jun 6, 2023

Conversation

gnawf
Copy link
Contributor

@gnawf gnawf commented Jun 6, 2023

No description provided.

*/
@SuppressWarnings({"unchecked", "rawtypes"})
private Set<GraphQLInterfaceType> getInterfacesCommonToAllOutputTypes(GraphQLSchema schema) {
Ref<Set<GraphQLInterfaceType>> ref = new Ref<>();
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need this Ref class?

Set> set = null;

if (set = null) {
set = new LinkedHashSet()
} else {
set.retainAll(x)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's Java. Can't touch non (effectively) final variables from inside lambdas.

(This gets used inside the forEachFieldDefinitions lambda).

It's basically a replacement for AtomicReference or Set<GraphQLInterfaceType>[] but more performant.

I will however move this down closer to the lambda usage.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh I get it - another trick is an array with one entry

Set<GraphQLInterfaceType> ref[] = {null}

and then use the one entry in a mutable way.

I like your approach.

@Internal
public class Ref<T> {
public T value;
}
Copy link
Member

Choose a reason for hiding this comment

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

I dont see how this is useful?

Copy link
Member

Choose a reason for hiding this comment

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

I get it now

Copy link
Member

Choose a reason for hiding this comment

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

Maybe if this was named MutableRef it might be clearer on how it can be used

@gnawf
Copy link
Contributor Author

gnawf commented Jun 6, 2023

Benchmarks using a large query.

Old code

Benchmark                                            Mode  Cnt    Score   Error  Units
AstCompilerBenchmark.benchMarkAstPrinterThroughput  thrpt   15  253.471 ± 4.965  ops/s

New code

Benchmark                                            Mode  Cnt    Score    Error  Units
AstCompilerBenchmark.benchMarkAstPrinterThroughput  thrpt   15  414.082 ± 46.620  ops/s

@gnawf gnawf marked this pull request as ready for review June 6, 2023 23:36
@gnawf gnawf requested a review from bbakerman June 6, 2023 23:36
Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Small naming suggestion on Ref - I like how this changed no tests and it still works

I am pretty sure there is lots of conditional tests

@bbakerman bbakerman added this pull request to the merge queue Jun 6, 2023
Merged via the queue into graphql-java:master with commit dedcc87 Jun 6, 2023
1 check passed
@bbakerman bbakerman added this to the 2023 July milestone Jun 6, 2023
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.

None yet

2 participants