From d8374148d6f3210121926662f5de4e6e53549ca0 Mon Sep 17 00:00:00 2001 From: Cam McHenry Date: Fri, 30 Oct 2026 12:26:34 -0400 Subject: [PATCH] perf(linter): lazily normalize capitalized-comments text (#28481) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of eagerly normalizing text (causing allocations), only normalize text when first accessed. On local fixtures: Metric | Before → After -- | -- Allocations | 187,675 → 157,156 (−16.3%) Allocated bytes | 17,279,585 → 15,605,488 (−9.7%) Maximum peak bytes | 11,334,860 → 11,334,440 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- crates/oxc_linter/src/rules/eslint/capitalized_comments.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/eslint/capitalized_comments.rs b/crates/oxc_linter/src/rules/eslint/capitalized_comments.rs index e2b798ec3a..60790216a6 100644 --- a/crates/oxc_linter/src/rules/eslint/capitalized_comments.rs +++ b/crates/oxc_linter/src/rules/eslint/capitalized_comments.rs @@ -1,3 +1,5 @@ +use std::cell::LazyCell; + use lazy_regex::{Regex, RegexBuilder}; use schemars::JsonSchema; use serde::Deserialize; @@ -207,7 +209,7 @@ impl Rule for CapitalizedComments { // Normalize the content: remove leading whitespace and JSDoc-style * markers // This is what ESLint calls "getTextWithoutAsterisks" - let normalized = normalize_comment_text(content); + let normalized = LazyCell::new(|| normalize_comment_text(content)); // Find the first letter position in original content let Some((first_letter_offset, first_letter)) = find_first_letter(content) else {