Skip to content

perf(hmr): remove unnecessary string allocations#10422

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/07-23-perf_hmr_remove_unnecessary_string_allocations
Jul 24, 2026
Merged

perf(hmr): remove unnecessary string allocations#10422
graphite-app[bot] merged 1 commit into
mainfrom
om/07-23-perf_hmr_remove_unnecessary_string_allocations

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Follow-on after #10018, continuation of #10420 and #10421.

When converting &'static strs to Strs, use Str::from instead of Str::from_str_in. The difference is that from_str_in performs an allocation (in arena), whereas from is a zero-cost no-op conversion at runtime. When the &str already has a 'static lifetime, it's unnecessary to extend it by allocating it into arena.

Before:

TemplateElementValue {
  raw: Str::from_str_in("/@vite/lazy?id=", &self.ast_builder),
  cooked: None,
}

After:

TemplateElementValue { raw: Str::from("/@vite/lazy?id="), cooked: None }

overlookmotel commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes HMR AST construction by avoiding arena allocations when converting 'static string literals into Oxc Str, using Str::from (borrowed, zero-cost) instead of Str::from_str_in (arena-allocating). This follows the earlier AST construction migration work and continues the string-allocation cleanup in the HMR path.

Changes:

  • Replace from_str_in with Str::from for 'static string literals in HMR AST builder helpers.
  • Avoid arena allocations for template literal quasi raw strings used to build the /@vite/lazy?... URL in the HMR lazy proxy rewrite.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/rolldown/src/hmr/utils.rs Uses ast::Str::from for a 'static module exports binding name to avoid arena allocation.
crates/rolldown/src/hmr/hmr_ast_finalizer.rs Uses Str::from for 'static template literal quasi strings to avoid arena allocation in lazy proxy URL construction.

@codspeed-hq

codspeed-hq Bot commented Jul 23, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing om/07-23-perf_hmr_remove_unnecessary_string_allocations (f677ba7) with om/07-23-perf_avoid_allocating_static_strings_via_custom_builder_methods (b0f8850)2

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on om/07-23-perf_avoid_allocating_static_strings_via_custom_builder_methods (45449fc) during the generation of this report, so ff68cbe was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel
overlookmotel force-pushed the om/07-23-perf_hmr_remove_unnecessary_string_allocations branch from 9d0b7c0 to f677ba7 Compare July 24, 2026 00:02
@overlookmotel
overlookmotel force-pushed the om/07-23-perf_avoid_allocating_static_strings_via_custom_builder_methods branch from b0f8850 to 45449fc Compare July 24, 2026 00:02

@hyfdev hyfdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

— Review by @hyfdev, assisted by GPT-5

@graphite-app

graphite-app Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merge activity

Follow-on after #10018, continuation of #10420 and #10421.

When converting `&'static str`s to `Str`s, use `Str::from` instead of `Str::from_str_in`. The difference is that `from_str_in` performs an allocation (in arena), whereas `from` is a zero-cost no-op conversion at runtime. When the `&str` already has a `'static` lifetime, it's unnecessary to extend it by allocating it into arena.

Before:

```rs
TemplateElementValue {
  raw: Str::from_str_in("/@vite/lazy?id=", &self.ast_builder),
  cooked: None,
}
```

After:

```rs
TemplateElementValue { raw: Str::from("/@vite/lazy?id="), cooked: None }
```
@graphite-app
graphite-app Bot force-pushed the om/07-23-perf_avoid_allocating_static_strings_via_custom_builder_methods branch from 45449fc to c6cf426 Compare July 24, 2026 03:45
@graphite-app
graphite-app Bot force-pushed the om/07-23-perf_hmr_remove_unnecessary_string_allocations branch from f677ba7 to 89ec37d Compare July 24, 2026 03:45
Base automatically changed from om/07-23-perf_avoid_allocating_static_strings_via_custom_builder_methods to main July 24, 2026 03:56
@graphite-app
graphite-app Bot merged commit 89ec37d into main Jul 24, 2026
32 checks passed
@graphite-app
graphite-app Bot deleted the om/07-23-perf_hmr_remove_unnecessary_string_allocations branch July 24, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants