mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
perf(lsp): improve some tsc op hot paths (#13473)
This commit is contained in:
parent
3ec248cff8
commit
1a3983a538
3 changed files with 33 additions and 19 deletions
|
@ -724,9 +724,9 @@ impl FileSystemDocuments {
|
|||
&mut self,
|
||||
cache: &HttpCache,
|
||||
maybe_resolver: Option<&dyn deno_graph::source::Resolver>,
|
||||
specifier: ModuleSpecifier,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<Document> {
|
||||
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<Document> {
|
||||
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()
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2373,13 +2373,13 @@ struct SpecifierArgs {
|
|||
}
|
||||
|
||||
fn op_exists(state: &mut State, args: SpecifierArgs) -> Result<bool, AnyError> {
|
||||
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<Option<String>, 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
|
||||
|
|
Loading…
Reference in a new issue