From 193286f19b9e2b975270f744aba4ba85ab1f2a47 Mon Sep 17 00:00:00 2001 From: Meemaw Date: Sat, 17 Oct 2026 21:50:45 +0200 Subject: [PATCH] Fix TwitterBenchmark which only measured a validation error The benchmark query is 150 levels deep, but since validation started enforcing QueryComplexityLimits (default maxDepth=100) every execution failed with MaxQueryDepthExceeded and returned no data. The benchmark was therefore measuring a cached validation error (~8M ops/s) rather than execution. Raise the max depth for the benchmark requests via the GraphQLContext and fail fast at class initialisation if the query does not execute cleanly, so the benchmark cannot silently regress like this again. Co-Authored-By: Claude Opus 5.5 --- src/jmh/java/benchmark/TwitterBenchmark.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/jmh/java/benchmark/TwitterBenchmark.java b/src/jmh/java/benchmark/TwitterBenchmark.java index 8fe58b0822..2ea1a09190 100644 --- a/src/jmh/java/benchmark/TwitterBenchmark.java +++ b/src/jmh/java/benchmark/TwitterBenchmark.java @@ -13,6 +13,7 @@ import graphql.schema.GraphQLObjectType; import graphql.schema.GraphQLSchema; import graphql.schema.GraphQLTypeReference; +import graphql.validation.QueryComplexityLimits; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -31,6 +32,7 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; +import static graphql.Assert.assertTrue; import static graphql.Scalars.GraphQLString; @Warmup(iterations = 2, time = 5) @@ -44,6 +46,17 @@ public class TwitterBenchmark { static Object queryId = "QUERY_ID"; static GraphQL graphQL = buildGraphQL(); + // the query is deliberately deeper than the default max depth enforced by validation + private static final QueryComplexityLimits LIMITS = QueryComplexityLimits.newLimits() + .maxDepth(DEPTH + 1) + .build(); + + static { + // fail fast rather than silently benchmarking a validation error + ExecutionResult result = execute(); + assertTrue(result.getErrors().isEmpty(), "TwitterBenchmark query failed: %s", result.getErrors()); + } + @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.SECONDS) @@ -58,7 +71,11 @@ public void benchmarkAvgTime(Blackhole bh) { } private static ExecutionResult execute() { - return graphQL.execute(query); + ExecutionInput executionInput = ExecutionInput.newExecutionInput() + .query(query) + .graphQLContext(ctx -> ctx.put(QueryComplexityLimits.KEY, LIMITS)) + .build(); + return graphQL.execute(executionInput); } public static String mkQuery() {