Skip to content

Commit 31bf28f

Browse files
JoviDeCroockbenjie
andauthored
Increase print/visit performance (#4312)
This replaces our expensive method that changes the underlying V8 shape multiple times with a loop that preserves the identity as much as possible. ``` ⏱ Print kitchen sink document 1 tests completed. 2 tests completed. HEAD x 9,290 ops/sec ±0.21% x 1.51 KB/op (24 runs sampled) BASE x 2,645 ops/sec ±0.18% x 2.18 KB/op (11 runs sampled) ``` --------- Co-authored-by: Benjie <[email protected]>
1 parent 90ebe5a commit 31bf28f

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed

benchmark/fixtures.js

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ exports.bigSchemaSDL = fs.readFileSync(
88
'utf8',
99
);
1010

11+
exports.bigDocumentSDL = fs.readFileSync(
12+
path.join(__dirname, 'kitchen-sink.graphql'),
13+
'utf8',
14+
);
15+
1116
exports.bigSchemaIntrospectionResult = JSON.parse(
1217
fs.readFileSync(path.join(__dirname, 'github-schema.json'), 'utf8'),
1318
);

benchmark/kitchen-sink.graphql

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
query queryName($foo: ComplexType, $site: Site = MOBILE) @onQuery {
2+
whoever123is: node(id: [123, 456]) {
3+
id
4+
... on User @onInlineFragment {
5+
field2 {
6+
id
7+
alias: field1(first: 10, after: $foo) @include(if: $foo) {
8+
id
9+
...frag @onFragmentSpread
10+
}
11+
}
12+
}
13+
... @skip(unless: $foo) {
14+
id
15+
}
16+
... {
17+
id
18+
}
19+
}
20+
}
21+
22+
mutation likeStory @onMutation {
23+
like(story: 123) @onField {
24+
story {
25+
id @onField
26+
}
27+
}
28+
}
29+
30+
subscription StoryLikeSubscription(
31+
$input: StoryLikeSubscribeInput @onVariableDefinition
32+
) @onSubscription {
33+
storyLikeSubscribe(input: $input) {
34+
story {
35+
likers {
36+
count
37+
}
38+
likeSentence {
39+
text
40+
}
41+
}
42+
}
43+
}
44+
45+
fragment frag on Friend @onFragmentDefinition {
46+
foo(
47+
size: $size
48+
bar: $b
49+
obj: {
50+
key: "value"
51+
block: """
52+
block string uses \"""
53+
"""
54+
}
55+
)
56+
}
57+
58+
{
59+
unnamed(truthy: true, falsy: false, nullish: null)
60+
query
61+
}
62+
63+
query {
64+
__typename
65+
}

benchmark/printer-benchmark.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const { parse } = require('graphql/language/parser.js');
4+
const { print } = require('graphql/language/printer.js');
5+
6+
const { bigDocumentSDL } = require('./fixtures.js');
7+
8+
const document = parse(bigDocumentSDL);
9+
10+
module.exports = {
11+
name: 'Print kitchen sink document',
12+
count: 1000,
13+
measure() {
14+
print(document);
15+
},
16+
};

src/language/visitor.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ export function visit(
222222
}
223223
}
224224
} else {
225-
node = Object.defineProperties(
226-
{},
227-
Object.getOwnPropertyDescriptors(node),
228-
);
225+
node = { ...node };
229226
for (const [editKey, editValue] of edits) {
230227
node[editKey] = editValue;
231228
}

0 commit comments

Comments
 (0)