Skip to content

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
@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.

2 participants