Skip to content

Commit 44466c4

Browse files
authored
chore(compiler): Add benchmark for parsing and validation when a type has many extensions (#1000)
Introduces a new benchmark for query parsing and validation when a type has many extensions. We made an update in `[email protected]` to expose `.iter_origins()` for AST nodes, and we reimplemented `.extensions()` in terms of `.iter_origins()`. We were concerned that this may have caused a performance regression in parsing, but running this new benchmark against `main` with `1.28.0` as the base indicates no change in performance: ``` many_extensions time: [9.4118 ms 9.4420 ms 9.4842 ms] change: [−0.3722% +1.0521% +2.1863%] (p = 0.11 > 0.05) No change in performance detected. Found 7 outliers among 100 measurements (7.00%) 3 (3.00%) high mild 4 (4.00%) high severe ```
1 parent 5357b58 commit 44466c4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/apollo-compiler/benches/fields_validation.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,43 @@ fn bench_many_types(c: &mut Criterion) {
114114
});
115115
}
116116

117+
fn bench_many_extensions(c: &mut Criterion) {
118+
let num_extensions = 10_000;
119+
let mut schema = String::new();
120+
schema.push_str("type Query { a: A }\n");
121+
for i in 1..=num_extensions {
122+
schema.push_str(&format!("interface I{i} {{ f{i}: String }}\n"));
123+
}
124+
schema.push_str("type A { f0: String }\n");
125+
for i in 1..=num_extensions {
126+
schema.push_str(&format!(
127+
"extend type A implements I{i} {{ f{i}: String }}\n"
128+
));
129+
}
130+
let schema = Schema::parse_and_validate(&schema, "schema.graphql").unwrap();
131+
132+
let mut query = String::new();
133+
query.push_str("{ a { ");
134+
for i in 1..=num_extensions {
135+
query.push_str(&format!("f{i} "));
136+
}
137+
query.push_str("} }");
138+
139+
c.bench_function("many_extensions", move |b| {
140+
b.iter(|| {
141+
let doc =
142+
ExecutableDocument::parse_and_validate(&schema, &query, "query.graphql").unwrap();
143+
std::hint::black_box(doc);
144+
});
145+
});
146+
}
147+
117148
criterion_group!(
118149
fields,
119150
bench_many_same_field,
120151
bench_many_same_nested_field,
121152
bench_many_arguments,
122153
bench_many_types,
154+
bench_many_extensions,
123155
);
124156
criterion_main!(fields);

0 commit comments

Comments
 (0)