Skip to content

Commit ea585a9

Browse files
authored
perf(linter): speed up noPrivateImports (#7461)
1 parent 7c2280b commit ea585a9

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Improved performance of `noPrivateImports` by eliminating allocations.
6+
7+
In one repository, the total runtime of Biome with only `noPrivateImports` enabled went from ~3.2s down to ~1.4s.

crates/biome_js_analyze/src/lint/correctness/no_private_imports.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub struct NoPrivateImportsState {
151151
range: TextRange,
152152

153153
/// The path where the visibility of the imported symbol is defined.
154-
path: Box<str>,
154+
path: String,
155155

156156
/// The visibility of the offending symbol.
157157
visibility: Visibility,
@@ -271,15 +271,13 @@ fn get_restricted_imports_from_module_source(
271271
node: &JsModuleSource,
272272
options: &GetRestrictedImportOptions,
273273
) -> SyntaxResult<Vec<NoPrivateImportsState>> {
274-
let path: Box<str> = options.target_path.as_str().into();
275-
276274
let results = match node.syntax().parent().and_then(AnyJsImportClause::cast) {
277275
Some(AnyJsImportClause::JsImportCombinedClause(node)) => {
278276
let range = node.default_specifier()?.range();
279277
get_restricted_import_visibility(&Text::new_static("default"), options)
280278
.map(|visibility| NoPrivateImportsState {
281279
range,
282-
path: path.clone(),
280+
path: options.target_path.to_string(),
283281
visibility,
284282
})
285283
.into_iter()
@@ -298,7 +296,7 @@ fn get_restricted_imports_from_module_source(
298296
)
299297
.map(|visibility| NoPrivateImportsState {
300298
range: name.text_trimmed_range(),
301-
path: path.clone(),
299+
path: options.target_path.to_string(),
302300
visibility,
303301
})
304302
}),
@@ -310,7 +308,7 @@ fn get_restricted_imports_from_module_source(
310308
get_restricted_import_visibility(&Text::new_static("default"), options)
311309
.map(|visibility| NoPrivateImportsState {
312310
range,
313-
path,
311+
path: options.target_path.to_string(),
314312
visibility,
315313
})
316314
.into_iter()
@@ -326,7 +324,7 @@ fn get_restricted_imports_from_module_source(
326324
get_restricted_import_visibility(&Text::from(name.token_text_trimmed()), options)
327325
.map(|visibility| NoPrivateImportsState {
328326
range: name.text_trimmed_range(),
329-
path: path.clone(),
327+
path: options.target_path.to_string(),
330328
visibility,
331329
})
332330
})

0 commit comments

Comments
 (0)