perf(hmr): remove unnecessary string allocations#10422
Conversation
How to use the Graphite Merge QueueAdd 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. |
There was a problem hiding this comment.
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_inwithStr::fromfor'staticstring literals in HMR AST builder helpers. - Avoid arena allocations for template literal quasi
rawstrings 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. |
Merging this PR will not alter performance
Comparing Footnotes
|
9d0b7c0 to
f677ba7
Compare
b0f8850 to
45449fc
Compare
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 } ```
45449fc to
c6cf426
Compare
f677ba7 to
89ec37d
Compare

Follow-on after #10018, continuation of #10420 and #10421.
When converting
&'static strs toStrs, useStr::frominstead ofStr::from_str_in. The difference is thatfrom_str_inperforms an allocation (in arena), whereasfromis a zero-cost no-op conversion at runtime. When the&stralready has a'staticlifetime, it's unnecessary to extend it by allocating it into arena.Before:
After: