From 6718be87c8468b8ed27548e350c62ad86287a900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 29 Nov 2023 22:18:23 +0100 Subject: [PATCH] perf(lsp): add performance marks for TSC requests (#21383) This should help us get a better picture where most of the time is spent (the TSC or the surrounding Rust code). --- cli/lsp/tsc.rs | 14 +++++++++++--- cli/tests/integration/lsp_tests.rs | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index e664c1b0ec..b67b634e1a 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -208,6 +208,7 @@ fn normalize_diagnostic( #[derive(Clone, Debug)] pub struct TsServer { + performance: Arc, sender: mpsc::UnboundedSender, specifier_map: Arc, } @@ -217,8 +218,9 @@ impl TsServer { let specifier_map = Arc::new(TscSpecifierMap::new()); let specifier_map_ = specifier_map.clone(); let (tx, mut rx) = mpsc::unbounded_channel::(); + let perf = performance.clone(); let _join_handle = thread::spawn(move || { - let mut ts_runtime = js_runtime(performance, cache, specifier_map_); + let mut ts_runtime = js_runtime(perf, cache, specifier_map_); let runtime = create_basic_runtime(); runtime.block_on(async { @@ -238,6 +240,7 @@ impl TsServer { }); Self { + performance, sender: tx, specifier_map, } @@ -946,9 +949,14 @@ impl TsServer { where R: de::DeserializeOwned, { - self + let mark = self + .performance + .mark(format!("tsc {}", req.method), None::<()>); + let r = self .request_with_cancellation(snapshot, req, Default::default()) - .await + .await; + self.performance.measure(mark); + r } async fn request_with_cancellation( diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index be3c3c0ad2..49b8bb4950 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -8309,6 +8309,10 @@ fn lsp_performance() { "op_load", "request", "testing_update", + "tsc $configure", + "tsc $getAssets", + "tsc $getSupportedCodeFixes", + "tsc getQuickInfoAtPosition", "update_cache", "update_diagnostics_deps", "update_diagnostics_lint",