Skip to content

Commit

Permalink
perf(hstr): Skip interning if the text is long enough (#10035)
Browse files Browse the repository at this point in the history
**Description:**

Almost all long strings are likely to differ, so there's no worth interning them. Those are mostly template literals in the case of SWC, but I didn't see any instance of very long text being identical to other instances.

**Related issue:**

 - Closes #10031
  • Loading branch information
kdy1 authored Feb 14, 2025
1 parent 2bea793 commit 2622e4e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/hstr/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ pub(crate) trait Storage {
impl Storage for &'_ mut AtomStore {
#[inline(never)]
fn insert_entry(self, text: Cow<str>, hash: u64) -> Item {
// If the text is too long, interning is not worth it.
if text.len() > 512 {
return Item(ThinArc::from_header_and_slice(
HeaderWithLength::new(Metadata { hash }, text.len()),
text.as_bytes(),
));
}

let (entry, _) = self
.data
.raw_entry_mut()
Expand Down

0 comments on commit 2622e4e

Please sign in to comment.