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 LSP benchmark mimicking the one on quick-lint-js #13365

Merged
merged 15 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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.

7 changes: 7 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ name = "deno_bench"
harness = false
path = "./bench/main.rs"

[[bench]]
name = "lsp_bench_standalone"
harness = false
path = "./bench/lsp_bench_standalone.rs"

[build-dependencies]
deno_broadcast_channel = { version = "0.25.0", path = "../ext/broadcast_channel" }
deno_console = { version = "0.31.0", path = "../ext/console" }
Expand Down Expand Up @@ -100,6 +105,8 @@ pretty_assertions = "=0.7.2"
test_util = { path = "../test_util" }
trust-dns-client = "=0.20.3"
trust-dns-server = "=0.20.3"
deno_bench_util = { version = "0.25.0", path = "../bench_util" }


[target.'cfg(unix)'.dev-dependencies]
nix = "=0.22.1"
Expand Down
75 changes: 75 additions & 0 deletions cli/bench/lsp_bench_standalone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use deno_bench_util::bencher::benchmark_group;
use deno_bench_util::bencher::benchmark_main;
use deno_bench_util::bencher::Bencher;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;

// Intended to match the benchmark in quick-lint-js
// https://github.com/quick-lint/quick-lint-js/blob/35207e6616267c6c81be63f47ce97ec2452d60df/benchmark/benchmark-lsp/lsp-benchmarks.cpp#L223-L268
fn incremental_change_wait(bench: &mut Bencher) {
let deno_exe = test_util::deno_exe_path();
let mut client = test_util::lsp::LspClient::new(&deno_exe).unwrap();

static FIXTURE_INIT_JSON: &[u8] =
include_bytes!("testdata/initialize_params.json");
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON).unwrap();
let (_, maybe_err) = client
.write_request::<_, _, Value>("initialize", params)
.unwrap();
assert!(maybe_err.is_none());
client.write_notification("initialized", json!({})).unwrap();

client
.write_notification(
"textDocument/didOpen",
json!({
"textDocument": {
"uri": "file:///testdata/express-router.js",
"languageId": "javascript",
"version": 0,
"text": include_str!("testdata/express-router.js")
}
}),
)
.unwrap();
let (method, maybe_diag): (String, Option<Value>) =
client.read_notification().unwrap();
assert_eq!(method, "textDocument/publishDiagnostics");
let _expected_num_diagnostics = get_num_diagnostics(maybe_diag);

let mut version = 0;
bench.iter(|| {
let text = format!("m{:05}", version);
client
.write_notification(
"textDocument/didChange",
json!({
"textDocument": {
"version": version,
"uri":"file:///testdata/express-router.js"
},
"contentChanges":[
{"text": text, "range":{"start":{"line":506,"character":39},"end":{"line":506,"character":45}}},
{"text": text, "range":{"start":{"line":507,"character":8},"end":{"line":507,"character":14}}},
{"text": text, "range":{"start":{"line":509,"character":10},"end":{"line":509,"character":16}}}
]
})
).unwrap();
let (method, maybe_diag): (String, Option<Value>) =
client.read_notification().unwrap();
ry marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(method, "textDocument/publishDiagnostics");
let _num_diagnostics = get_num_diagnostics(maybe_diag);
//assert_eq!(num_diagnostics, expected_num_diagnostics);
version += 1;
})
}

fn get_num_diagnostics(maybe_diag: Option<Value>) -> usize {
let d = maybe_diag.unwrap();
let msg = d.as_object().unwrap();
msg.get("diagnostics").unwrap().as_array().unwrap().len()
}

benchmark_group!(benches, incremental_change_wait);
benchmark_main!(benches);
Loading