Skip to content

Commit 98f9eee

Browse files
authored
Remove Salsa database for 1.2× ~ 2× validation speed (#838)
1 parent 41b69c2 commit 98f9eee

40 files changed

+945
-1910
lines changed

crates/apollo-compiler/CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,34 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1717
## Maintenance
1818
## Documentation-->
1919

20+
# [x.x.x] (unreleased) - 2024-mm-dd
21+
22+
## BREAKING
23+
24+
- **Move `NodeLocation` and `FileId` from `apollo_compiler::validation` to the crate root - [SimonSapin], [pull/838]**
25+
26+
## Maintenance
27+
28+
- **Remove Salsa database for 1.2× ~ 2× validation speed - [SimonSapin], [pull/838]**
29+
We were not taking advantage of caching it provides.
30+
Additionally, validation uses `Schema` and `ExecutableDocument` directly
31+
rather than converting them to AST.
32+
```
33+
$ cargo bench --bench multi-source
34+
supergraph parse_and_validate
35+
time: [398.09 µs 399.32 µs 400.82 µs]
36+
change: [-19.966% -19.418% -18.864%] (p = 0.00 < 0.05)
37+
Performance has improved.
38+
simple_query parse_and_validate
39+
time: [12.097 µs 12.104 µs 12.113 µs]
40+
change: [-52.467% -52.282% -52.109%] (p = 0.00 < 0.05)
41+
Performance has improved.
42+
```
43+
44+
[SimonSapin]: https://github.com/SimonSapin]
45+
[pull/838]: https://github.com/apollographql/apollo-rs/pull/838
46+
47+
2048
# [1.0.0-beta.13](https://crates.io/crates/apollo-compiler/1.0.0-beta.13) - 2024-02-14
2149

2250
> This release includes a critical fix to overflow protection in validation.

crates/apollo-compiler/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ apollo-parser = { path = "../apollo-parser", version = "0.7.6" }
2222
ariadne = { version = "0.4.0", features = ["auto-color"] }
2323
indexmap = "2.0.0"
2424
rowan = "0.15.5"
25-
salsa = "0.16.1"
2625
serde = { version = "1.0", features = ["derive"] }
2726
serde_json_bytes = { version = "0.2.2", features = ["preserve_order"] }
2827
thiserror = "1.0.31"
+16-32
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,43 @@
1+
use apollo_compiler::ast::Document;
12
use apollo_compiler::ExecutableDocument;
23
use apollo_compiler::Schema;
34
use criterion::*;
45

5-
fn compile(schema: &str, query: &str) {
6-
let schema = Schema::parse_and_validate(schema, "schema.graphql").unwrap();
7-
let doc = ExecutableDocument::parse(&schema, query, "query.graphql").unwrap();
6+
fn parse_ast(schema: &str, query: &str) {
7+
let schema = Document::parse(schema, "schema.graphql").unwrap();
8+
let doc = Document::parse(query, "query.graphql").unwrap();
89
black_box((schema, doc));
910
}
1011

11-
fn compile_and_validate(schema: &str, query: &str) {
12+
fn parse_and_validate(schema: &str, query: &str) {
1213
let schema = Schema::parse_and_validate(schema, "schema.graphql").unwrap();
1314
let doc = ExecutableDocument::parse_and_validate(&schema, query, "query.graphql").unwrap();
1415
black_box((schema, doc));
1516
}
1617

17-
fn bench_simple_query_compiler(c: &mut Criterion) {
18+
fn bench_simple_query(c: &mut Criterion) {
1819
let query = include_str!("testdata/simple_query.graphql");
1920
let schema = include_str!("testdata/simple_schema.graphql");
2021

21-
c.bench_function("simple_query_compiler", move |b| {
22-
b.iter(|| compile(schema, query))
22+
c.bench_function("simple_query parse_ast", move |b| {
23+
b.iter(|| parse_ast(schema, query))
2324
});
24-
}
25-
26-
fn bench_simple_query_compiler_with_validation(c: &mut Criterion) {
27-
let query = include_str!("testdata/simple_query.graphql");
28-
let schema = include_str!("testdata/simple_schema.graphql");
29-
30-
c.bench_function("simple_query_compiler_with_validation", move |b| {
31-
b.iter(|| compile_and_validate(schema, query))
25+
c.bench_function("simple_query parse_and_validate", move |b| {
26+
b.iter(|| parse_and_validate(schema, query))
3227
});
3328
}
3429

35-
fn bench_compiler_supergraph(c: &mut Criterion) {
30+
fn bench_supergraph(c: &mut Criterion) {
3631
let schema = include_str!("testdata/supergraph.graphql");
3732
let query = include_str!("testdata/supergraph_query.graphql");
3833

39-
c.bench_function("supergraph_compiler", move |b| {
40-
b.iter(|| compile(schema, query))
34+
c.bench_function("supergraph parse_ast", move |b| {
35+
b.iter(|| parse_ast(schema, query))
4136
});
42-
}
43-
fn bench_compiler_supergraph_with_validation(c: &mut Criterion) {
44-
let schema = include_str!("testdata/supergraph.graphql");
45-
let query = include_str!("testdata/supergraph_query.graphql");
46-
47-
c.bench_function("supergraph_compiler_with_validation", move |b| {
48-
b.iter(|| compile_and_validate(schema, query))
37+
c.bench_function("supergraph parse_and_validate", move |b| {
38+
b.iter(|| parse_and_validate(schema, query))
4939
});
5040
}
5141

52-
criterion_group!(
53-
benches,
54-
bench_compiler_supergraph,
55-
bench_compiler_supergraph_with_validation,
56-
bench_simple_query_compiler,
57-
bench_simple_query_compiler_with_validation
58-
);
42+
criterion_group!(benches, bench_supergraph, bench_simple_query);
5943
criterion_main!(benches);

crates/apollo-compiler/src/ast/from_cst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::ast;
22
use crate::ast::Document;
33
use crate::validation::FileId;
4-
use crate::validation::NodeLocation;
54
use crate::Node;
5+
use crate::NodeLocation;
66
use crate::SourceMap;
77
use apollo_parser::cst;
88
use apollo_parser::cst::CstNode;

crates/apollo-compiler/src/ast/impls.rs

-80
Original file line numberDiff line numberDiff line change
@@ -470,51 +470,30 @@ impl DirectiveDefinition {
470470
impl SchemaDefinition {
471471
serialize_method!();
472472
}
473-
impl Extensible for SchemaDefinition {
474-
type Extension = SchemaExtension;
475-
}
476473

477474
impl ScalarTypeDefinition {
478475
serialize_method!();
479476
}
480-
impl Extensible for ScalarTypeDefinition {
481-
type Extension = ScalarTypeExtension;
482-
}
483477

484478
impl ObjectTypeDefinition {
485479
serialize_method!();
486480
}
487-
impl Extensible for ObjectTypeDefinition {
488-
type Extension = ObjectTypeExtension;
489-
}
490481

491482
impl InterfaceTypeDefinition {
492483
serialize_method!();
493484
}
494-
impl Extensible for InterfaceTypeDefinition {
495-
type Extension = InterfaceTypeExtension;
496-
}
497485

498486
impl UnionTypeDefinition {
499487
serialize_method!();
500488
}
501-
impl Extensible for UnionTypeDefinition {
502-
type Extension = UnionTypeExtension;
503-
}
504489

505490
impl EnumTypeDefinition {
506491
serialize_method!();
507492
}
508-
impl Extensible for EnumTypeDefinition {
509-
type Extension = EnumTypeExtension;
510-
}
511493

512494
impl InputObjectTypeDefinition {
513495
serialize_method!();
514496
}
515-
impl Extensible for InputObjectTypeDefinition {
516-
type Extension = InputObjectTypeExtension;
517-
}
518497

519498
impl SchemaExtension {
520499
serialize_method!();
@@ -1840,62 +1819,3 @@ impl fmt::Debug for InvalidNameError {
18401819
fmt::Display::fmt(self, f)
18411820
}
18421821
}
1843-
1844-
impl<T: Extensible> TypeWithExtensions<T> {
1845-
/// Iterate over elements of the base definition and its extensions.
1846-
pub fn iter_all<'a, Item, DefIter, ExtIter>(
1847-
&'a self,
1848-
mut map_definition: impl FnMut(&'a Node<T>) -> DefIter + 'a,
1849-
map_extension: impl FnMut(&'a Node<T::Extension>) -> ExtIter + 'a,
1850-
) -> impl Iterator<Item = Item> + 'a
1851-
where
1852-
Item: 'a,
1853-
DefIter: Iterator<Item = Item> + 'a,
1854-
ExtIter: Iterator<Item = Item> + 'a,
1855-
{
1856-
map_definition(&self.definition).chain(self.extensions.iter().flat_map(map_extension))
1857-
}
1858-
}
1859-
1860-
macro_rules! iter_extensible_method {
1861-
($property:ident, $ty:ty) => {
1862-
pub fn $property(&self) -> impl Iterator<Item = &'_ $ty> + '_ {
1863-
self.iter_all(
1864-
|definition| definition.$property.iter(),
1865-
|extension| extension.$property.iter(),
1866-
)
1867-
}
1868-
};
1869-
}
1870-
1871-
impl TypeWithExtensions<SchemaDefinition> {
1872-
iter_extensible_method!(directives, Node<Directive>);
1873-
iter_extensible_method!(root_operations, Node<(OperationType, NamedType)>);
1874-
}
1875-
1876-
impl TypeWithExtensions<ObjectTypeDefinition> {
1877-
iter_extensible_method!(directives, Node<Directive>);
1878-
iter_extensible_method!(fields, Node<FieldDefinition>);
1879-
iter_extensible_method!(implements_interfaces, NamedType);
1880-
}
1881-
1882-
impl TypeWithExtensions<InterfaceTypeDefinition> {
1883-
iter_extensible_method!(directives, Node<Directive>);
1884-
iter_extensible_method!(fields, Node<FieldDefinition>);
1885-
iter_extensible_method!(implements_interfaces, NamedType);
1886-
}
1887-
1888-
impl TypeWithExtensions<UnionTypeDefinition> {
1889-
iter_extensible_method!(directives, Node<Directive>);
1890-
iter_extensible_method!(members, NamedType);
1891-
}
1892-
1893-
impl TypeWithExtensions<EnumTypeDefinition> {
1894-
iter_extensible_method!(directives, Node<Directive>);
1895-
iter_extensible_method!(values, Node<EnumValueDefinition>);
1896-
}
1897-
1898-
impl TypeWithExtensions<InputObjectTypeDefinition> {
1899-
iter_extensible_method!(directives, Node<Directive>);
1900-
iter_extensible_method!(fields, Node<InputValueDefinition>);
1901-
}

crates/apollo-compiler/src/ast/mod.rs

-26
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
3434
use crate::Node;
3535
use crate::NodeStr;
36-
use std::collections::HashMap;
3736

3837
pub(crate) mod from_cst;
3938
pub(crate) mod impls;
@@ -363,28 +362,3 @@ pub struct FloatValue(String);
363362
#[derive(Clone, Eq, PartialEq)]
364363
#[non_exhaustive]
365364
pub struct FloatOverflowError {}
366-
367-
/// Trait implemented by extensible type definitions, to associate the extension type with the base
368-
/// definition type.
369-
pub(crate) trait Extensible {
370-
type Extension;
371-
}
372-
373-
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
374-
pub(crate) struct TypeWithExtensions<T: Extensible> {
375-
pub definition: Node<T>,
376-
pub extensions: Vec<Node<T::Extension>>,
377-
}
378-
379-
// TODO(@goto-bus-stop): may have to do Arc<TypeWithExtensions> as we need to clone
380-
// it for salsa reasons. OR pass (object|scalar|etc, Name) tuples to the salsa queries.
381-
#[derive(Debug, PartialEq, Eq)]
382-
pub(crate) struct TypeSystem {
383-
pub schema: TypeWithExtensions<SchemaDefinition>,
384-
pub objects: HashMap<Name, TypeWithExtensions<ObjectTypeDefinition>>,
385-
pub scalars: HashMap<Name, TypeWithExtensions<ScalarTypeDefinition>>,
386-
pub interfaces: HashMap<Name, TypeWithExtensions<InterfaceTypeDefinition>>,
387-
pub unions: HashMap<Name, TypeWithExtensions<UnionTypeDefinition>>,
388-
pub enums: HashMap<Name, TypeWithExtensions<EnumTypeDefinition>>,
389-
pub input_objects: HashMap<Name, TypeWithExtensions<InputObjectTypeDefinition>>,
390-
}

crates/apollo-compiler/src/database/db.rs

-24
This file was deleted.

crates/apollo-compiler/src/database/inputs.rs

-64
This file was deleted.

crates/apollo-compiler/src/database/mod.rs

-12
This file was deleted.

0 commit comments

Comments
 (0)