Skip to content

Commit 7df8e16

Browse files
authored
benchmark: add benchmark for schema validation (#4713)
also explicitly removes schema validation from execution benchmarks (although this would have been cached after warmup anyway)
1 parent 6ce253d commit 7df8e16

6 files changed

Lines changed: 31 additions & 4 deletions

benchmark/list-async-benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { execute } from 'graphql/execution/execute.js';
22
import { parse } from 'graphql/language/parser.js';
33
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
44

5-
const schema = buildSchema('type Query { listField: [String] }');
5+
const schema = buildSchema('type Query { listField: [String] }', {
6+
assumeValid: true,
7+
});
68
const document = parse('{ listField }');
79

810
function listField() {

benchmark/list-asyncIterable-benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { execute } from 'graphql/execution/execute.js';
22
import { parse } from 'graphql/language/parser.js';
33
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
44

5-
const schema = buildSchema('type Query { listField: [String] }');
5+
const schema = buildSchema('type Query { listField: [String] }', {
6+
assumeValid: true,
7+
});
68
const document = parse('{ listField }');
79

810
async function* listField() {

benchmark/list-sync-benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { execute } from 'graphql/execution/execute.js';
22
import { parse } from 'graphql/language/parser.js';
33
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
44

5-
const schema = buildSchema('type Query { listField: [String] }');
5+
const schema = buildSchema('type Query { listField: [String] }', {
6+
assumeValid: true,
7+
});
68
const document = parse('{ listField }');
79

810
function listField() {

benchmark/object-async-benchmark.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const fieldNames = Array.from(
1010

1111
const schema = buildSchema(
1212
`type Query { ${fieldNames.map((fieldName) => `${fieldName}: Int`).join(' ')} }`,
13+
{ assumeValid: true },
1314
);
1415

1516
const document = parse(`{ ${fieldNames.join(' ')} }`);

benchmark/repeated-fields-benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { graphqlSync } from 'graphql/graphql.js';
22
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
33

4-
const schema = buildSchema('type Query { hello: String! }');
4+
const schema = buildSchema('type Query { hello: String! }', {
5+
assumeValid: true,
6+
});
57
const source = `{ ${'hello '.repeat(250)}}`;
68

79
export const benchmark = {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { validateSchema } from 'graphql/type/validate.js';
2+
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
3+
4+
import { bigSchemaSDL } from './fixtures.js';
5+
6+
const schema = buildSchema(bigSchemaSDL, {
7+
assumeValidSDL: true,
8+
});
9+
10+
export const benchmark = {
11+
name: 'Validate Schema',
12+
measure: () => {
13+
// validateSchema caches results on the schema, so clear the cache to
14+
// measure validation itself without also measuring schema construction.
15+
schema.__validationErrors = undefined;
16+
return validateSchema(schema);
17+
},
18+
};

0 commit comments

Comments
 (0)