Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[build: suggestion] Performance improvement: Replace template literals with single quotes for static strings #20993

budarin started this conversation in General
Discussion options

Dear team,

I would like to bring to your attention a potential performance consideration regarding the current code generation strategy.

The rolldown-vite transpiler consistently uses template literals (backticks) for all string literals in the generated code, even when no variable interpolation is needed. For example:

import { n as e, r as t } from './rolldown-runtime-BHJ7HXw7.js';
import { n, r, t as i } from './react-6qhUHSxL.js';
import {
 a,
 c as o,
 i as s,
 l as c,
 n as l,
 o as u,
 r as d,
 s as f,
 t as ee,
} from './npm-Bu7_7IAJ.js';
(function () {
 let e = document.createElement(`link`).relList;
 if (e && e.supports && e.supports(`modulepreload`)) return;
 for (let e of document.querySelectorAll(`link[rel="modulepreload"]`)) n(e);
 new MutationObserver((e) => {
 for (let t of e)
 if (t.type === `childList`)
 for (let e of t.addedNodes)
 e.tagName === `LINK` && e.rel === `modulepreload` && n(e);
 }).observe(document, { childList: !0, subtree: !0 });
 function t(e) {
 let t = {};
 return (
 e.integrity && (t.integrity = e.integrity),
 e.referrerPolicy && (t.referrerPolicy = e.referrerPolicy),
 e.crossOrigin === `use-credentials`
 ? (t.credentials = `include`)
 : e.crossOrigin === `anonymous`
 ? (t.credentials = `omit`)
 : (t.credentials = `same-origin`),
 t
 );
 }
 function n(e) {
 if (e.ep) return;
 e.ep = !0;
 let n = t(e);
 fetch(e.href, n);
 }
})();

While the performance difference is minimal for individual string operations, template literals have a slight overhead compared to regular string literals due to:

  • Additional parsing for potential interpolation syntax
  • Slightly larger memory footprint
  • More complex string creation process

Proposal:

  • Uses single quotes for static strings without interpolation
  • Only uses template literals when actual variable interpolation is needed

"vite": "rolldown-vite v7.1.19"

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /