Skip to content

Commit 96cca22

Browse files
committed
perf(language_server): use simdutf8 when reading files from file system (#10814)
1 parent 0905767 commit 96cca22

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
fs,
32
path::{Path, PathBuf},
43
sync::{Arc, OnceLock},
54
};
@@ -14,7 +13,7 @@ use tower_lsp_server::{
1413
use oxc_allocator::Allocator;
1514
use oxc_linter::{
1615
LINTABLE_EXTENSIONS, LintService, LintServiceOptions, Linter, MessageWithPosition,
17-
loader::Loader,
16+
loader::Loader, read_to_string,
1817
};
1918

2019
use super::error_with_position::{
@@ -103,7 +102,7 @@ impl IsolatedLintHandler {
103102
debug!("extension not supported yet.");
104103
return None;
105104
}
106-
let source_text = source_text.or_else(|| fs::read_to_string(path).ok())?;
105+
let source_text = source_text.or_else(|| read_to_string(path).ok())?;
107106

108107
debug!("lint {path:?}");
109108

crates/oxc_linter/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub use crate::{
4444
options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind},
4545
rule::{RuleCategory, RuleFixMeta, RuleMeta, RuleWithSeverity},
4646
service::{LintService, LintServiceOptions},
47+
utils::read_to_string,
4748
};
4849
use crate::{
4950
config::{LintConfig, OxlintEnv, OxlintGlobals, OxlintSettings, ResolvedLinterState},

crates/oxc_linter/src/utils/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ pub fn is_eslint_rule_adapted_to_typescript(rule_name: &str) -> bool {
113113
TYPESCRIPT_COMPATIBLE_ESLINT_RULES.binary_search(&rule_name).is_ok()
114114
}
115115

116+
/// Reads the content of a path and returns it.
117+
/// This function is faster than native `fs:read_to_string`.
118+
///
119+
/// # Errors
120+
/// When the content of the path is not a valid UTF-8 bytes
116121
pub fn read_to_string(path: &Path) -> io::Result<String> {
117122
// `simdutf8` is faster than `std::str::from_utf8` which `fs::read_to_string` uses internally
118123
let bytes = std::fs::read(path)?;

0 commit comments

Comments
 (0)