diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 280b345c72..e200538971 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -724,9 +724,9 @@ impl FileSystemDocuments { &mut self, cache: &HttpCache, maybe_resolver: Option<&dyn deno_graph::source::Resolver>, - specifier: ModuleSpecifier, + specifier: &ModuleSpecifier, ) -> Option { - let path = get_document_path(cache, &specifier)?; + let path = get_document_path(cache, specifier)?; let fs_version = calculate_fs_version(&path)?; let bytes = fs::read(path).ok()?; let doc = if specifier.scheme() == "file" { @@ -741,11 +741,11 @@ impl FileSystemDocuments { maybe_resolver, ) } else { - let cache_filename = cache.get_cache_filename(&specifier)?; + let cache_filename = cache.get_cache_filename(specifier)?; let metadata = http_cache::Metadata::read(&cache_filename).ok()?; let maybe_content_type = metadata.headers.get("content-type").cloned(); let maybe_headers = Some(&metadata.headers); - let (_, maybe_charset) = map_content_type(&specifier, maybe_content_type); + let (_, maybe_charset) = map_content_type(specifier, maybe_content_type); let content = Arc::new(get_source_from_bytes(bytes, maybe_charset).ok()?); Document::new( specifier.clone(), @@ -756,7 +756,7 @@ impl FileSystemDocuments { ) }; self.dirty = true; - self.docs.insert(specifier, doc) + self.docs.insert(specifier.clone(), doc) } } @@ -949,6 +949,22 @@ impl Documents { } } + /// Used by the tsc op_exists to shortcut trying to load a document to provide + /// information to CLI without allocating a document. + pub(crate) fn exists(&self, specifier: &ModuleSpecifier) -> bool { + let specifier = self.specifier_resolver.resolve(specifier); + if let Some(specifier) = specifier { + if self.open_docs.contains_key(&specifier) { + return true; + } + if let Some(path) = get_document_path(&self.cache, &specifier) { + return path.is_file(); + } + } + + false + } + /// Return a document for the specifier. pub fn get(&self, specifier: &ModuleSpecifier) -> Option { let specifier = self.specifier_resolver.resolve(specifier)?; @@ -969,7 +985,7 @@ impl Documents { file_system_docs.refresh_document( &self.cache, self.get_maybe_resolver(), - specifier.clone(), + &specifier, ); } file_system_docs.docs.get(&specifier).cloned() diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs index 05e586ffdc..c8c4678090 100644 --- a/cli/lsp/performance.rs +++ b/cli/lsp/performance.rs @@ -83,7 +83,7 @@ impl Default for Performance { fn default() -> Self { Self { counts: Default::default(), - max_size: 1_000, + max_size: 3_000, measures: Default::default(), } } diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 2686465068..ffe1617818 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2373,13 +2373,13 @@ struct SpecifierArgs { } fn op_exists(state: &mut State, args: SpecifierArgs) -> Result { - let mark = state.performance.mark("op_exists", Some(&args)); + // we don't measure the performance of op_exists anymore because as of TS 4.5 + // it is noisy with all the checking for custom libs, that we can't see the + // forrest for the trees as well as it compounds any lsp performance + // challenges, opening a single document in the editor causes some 3k worth + // of op_exists requests... :omg: let specifier = state.normalize_specifier(args.specifier)?; - let result = state - .state_snapshot - .documents - .contains_specifier(&specifier); - state.performance.measure(mark); + let result = state.state_snapshot.documents.exists(&specifier); Ok(result) } @@ -2564,9 +2564,10 @@ fn op_script_version( state: &mut State, args: ScriptVersionArgs, ) -> Result, AnyError> { - let mark = state.performance.mark("op_script_version", Some(&args)); + // this op is very "noisy" and measuring its performance is not useful, so we + // don't measure it uniquely anymore. let specifier = state.normalize_specifier(args.specifier)?; - let r = if specifier.scheme() == "asset" { + if specifier.scheme() == "asset" { if state.state_snapshot.assets.contains_key(&specifier) { Ok(Some("1".to_string())) } else { @@ -2579,10 +2580,7 @@ fn op_script_version( .get(&specifier) .map(|d| d.script_version()); Ok(script_version) - }; - - state.performance.measure(mark); - r + } } /// Create and setup a JsRuntime based on a snapshot. It is expected that the