Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bench): add graphql parser #2836

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ biome_diagnostics_macros = { version = "0.5.7", path = "./crates/biome_diagn
biome_formatter = { version = "0.5.7", path = "./crates/biome_formatter" }
biome_fs = { version = "0.5.7", path = "./crates/biome_fs" }
biome_graphql_factory = { version = "0.1.0", path = "./crates/biome_graphql_factory" }
biome_graphql_parser = { version = "0.1.0", path = "./crates/biome_graphql_parser" }
biome_graphql_syntax = { version = "0.1.0", path = "./crates/biome_graphql_syntax" }
biome_grit_factory = { version = "0.5.7", path = "./crates/biome_grit_factory" }
biome_grit_parser = { version = "0.1.0", path = "./crates/biome_grit_parser" }
Expand Down
2 changes: 2 additions & 0 deletions xtask/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ biome_css_parser = { workspace = true }
biome_css_syntax = { workspace = true }
biome_diagnostics = { workspace = true }
biome_formatter = { workspace = true }
biome_graphql_parser = { workspace = true }
biome_graphql_syntax = { workspace = true }
biome_js_analyze = { workspace = true }
biome_js_formatter = { workspace = true }
biome_js_parser = { workspace = true }
Expand Down
40 changes: 40 additions & 0 deletions xtask/bench/benches/graphql_parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::collections::HashMap;
use xtask_bench::{bench_parser_group, TestCase};
use xtask_bench::{criterion_group, criterion_main, Criterion};
#[cfg(target_os = "windows")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[cfg(all(
any(target_os = "macos", target_os = "linux"),
not(target_env = "musl"),
))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

// Jemallocator does not work on aarch64 with musl, so we'll use the system allocator instead
#[cfg(all(target_env = "musl", target_os = "linux", target_arch = "aarch64"))]
#[global_allocator]
static GLOBAL: std::alloc::System = std::alloc::System;
fn bench_css_parser(criterion: &mut Criterion) {
let mut all_suites = HashMap::new();
all_suites.insert("graphql", include_str!("libs-graphql.txt"));
let mut libs = vec![];
libs.extend(all_suites.values().flat_map(|suite| suite.lines()));

let mut group = criterion.benchmark_group("graphql_parser");
for lib in libs {
let test_case = TestCase::try_from(lib);

match test_case {
Ok(test_case) => {
bench_parser_group(&mut group, test_case);
}
Err(e) => println!("{:?}", e),
}
}
group.finish();
}

criterion_group!(graphql_parser, bench_css_parser);
criterion_main!(graphql_parser);
3 changes: 3 additions & 0 deletions xtask/bench/benches/libs-graphql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://raw.githubusercontent.com/amplication/amplication/909a1a77cd52e7f362cb5e037b3928146cef2ae4/schema.graphql
https://raw.githubusercontent.com/dgraph-io/dgraph/2a3dacd849c912643949a5ae6d78258b6c8f71ab/graphql/e2e/normal/schema.graphql
https://raw.githubusercontent.com/superfly/flyctl/9255529e9f423e6aca6eba64457187b6aead53fa/gql/schema.graphql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is soo good!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is! I also found the schema of GitHub APIs, but it's 1.1MB ... 😅 It can wait I suppose

9 changes: 9 additions & 0 deletions xtask/bench/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum Parse<'a> {
JavaScript(JsFileSource, &'a str),
Json(&'a str),
Css(&'a str),
Graphql(&'a str),
}

impl<'a> Parse<'a> {
Expand Down Expand Up @@ -47,6 +48,7 @@ impl<'a> Parse<'a> {
code,
CssParserOptions::default().allow_wrong_line_comments(),
)),
Parse::Graphql(code) => Parsed::Graphql(biome_graphql_parser::parse_graphql(code)),
}
}

Expand All @@ -71,6 +73,9 @@ impl<'a> Parse<'a> {
cache,
CssParserOptions::default().allow_wrong_line_comments(),
)),
Parse::Graphql(code) => {
Parsed::Graphql(biome_graphql_parser::parse_graphql_with_cache(code, cache))
}
}
}
}
Expand All @@ -79,6 +84,7 @@ pub enum Parsed {
JavaScript(biome_js_parser::Parse<AnyJsRoot>, JsFileSource),
Json(biome_json_parser::JsonParse),
Css(biome_css_parser::CssParse),
Graphql(biome_graphql_parser::GraphqlParse),
}

impl Parsed {
Expand All @@ -89,13 +95,15 @@ impl Parsed {
}
Parsed::Json(parse) => Some(FormatNode::Json(parse.syntax())),
Parsed::Css(parse) => Some(FormatNode::Css(parse.syntax())),
Parsed::Graphql(parse) => None,
}
}

pub fn analyze(&self) -> Option<Analyze> {
match self {
Parsed::JavaScript(parse, _) => Some(Analyze::JavaScript(parse.tree())),
Parsed::Json(_) => None,
Parsed::Graphql(_) => None,
Parsed::Css(parse) => Some(Analyze::Css(parse.tree())),
}
}
Expand All @@ -105,6 +113,7 @@ impl Parsed {
Parsed::JavaScript(parse, _) => parse.into_diagnostics(),
Parsed::Json(parse) => parse.into_diagnostics(),
Parsed::Css(parse) => parse.into_diagnostics(),
Parsed::Graphql(parse) => parse.into_diagnostics(),
}
}
}
Expand Down
Loading