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

Add performance tests for bindings API #1100

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion crates/solidity/testing/perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ publish = false
[dev-dependencies]
iai-callgrind = { workspace = true }
semver = { workspace = true }
slang_solidity = { workspace = true }
metaslang_bindings = { workspace = true }
slang_solidity = { workspace = true, features = [
"__experimental_bindings_api",
] }

[[bench]]
name = "iai"
Expand Down
51 changes: 51 additions & 0 deletions crates/solidity/testing/perf/benches/iai/dataset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::BTreeSet;
use std::sync::Arc;

use metaslang_bindings::PathResolver;
use semver::Version;
use slang_solidity::bindings::{self, Bindings};
use slang_solidity::cst::Node;
use slang_solidity::kinds::{EdgeLabel, NonterminalKind};
use slang_solidity::language::Language;
Expand Down Expand Up @@ -243,3 +246,51 @@ pub fn run_query(trees: &Vec<Node>) {
"Function names don't match: {results:#?}"
);
}

struct NoOpResolver;

impl PathResolver for NoOpResolver {
fn resolve_path(&self, _context_path: &str, path_to_resolve: &str) -> Option<String> {
Some(path_to_resolve.to_string())
}
}

pub fn run_build_bindings(trees: &[Node]) -> Bindings {
let mut definition_count = 0_usize;
let mut bindings = bindings::create_with_resolver(SOLC_VERSION, Arc::new(NoOpResolver {}));

for (index, tree) in trees.iter().enumerate() {
let path = format!("input{index}.sol");
bindings.add_file(&path, tree.cursor_with_offset(TextIndex::ZERO));
definition_count += bindings.all_definitions().count();
}

assert!(
definition_count >= 723,
"Only found {definition_count} definitions"
);

bindings
}

pub fn run_resolve_references(bindings: &Bindings) {
let mut reference_count = 0_usize;
let mut resolved_references = 0_usize;

for reference in bindings.all_references() {
reference_count += 1;
let resolution = reference.jump_to_definition();
if resolution.is_ok() {
resolved_references += 1;
}
}

assert!(
reference_count >= 1491,
"Only found {reference_count} references"
);
assert!(
resolved_references >= 1170,
"Only resolved {resolved_references} references"
);
}
14 changes: 13 additions & 1 deletion crates/solidity/testing/perf/benches/iai/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use iai_callgrind::{
library_benchmark, library_benchmark_group, main, Direction, FlamegraphConfig,
LibraryBenchmarkConfig, Tool, ValgrindTool,
};
use slang_solidity::bindings::Bindings;
use slang_solidity::cst::Node;

#[library_benchmark]
Expand All @@ -32,10 +33,21 @@ fn query(trees: Vec<Node>) {
black_box(dataset::run_query(&trees));
}

#[library_benchmark(setup = dataset::run_parser)]
fn build_bindings(trees: Vec<Node>) {
black_box(dataset::run_build_bindings(&trees));
}

#[library_benchmark(setup = dataset::run_build_bindings)]
#[bench::run(args = (&dataset::run_parser()))]
fn resolve_references(bindings: Bindings) {
black_box(dataset::run_resolve_references(&bindings));
}

library_benchmark_group!(
name = benchmarks;

benchmarks = parser, cursor, query
benchmarks = parser, cursor, query, build_bindings, resolve_references
);

main!(
Expand Down
Loading