-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiling code with a large template literal without placeholders is slower than an equivalent string literal #41448
Comments
This is actually intended behavior, template strings don't act the exact same way as normal strings, when a template string is encountered, it is inspected to look for template literals ( And this inspection is done mainly by the V8 engine, not by the |
Indeed, the observation that got me to this issue is that a template literal containing a stringified object literal is (barely) slower than just using the object literal directly. The use case is files like https://github.com/yarnpkg/berry/blob/ce1e0c31781e3fc791cfa86a01348c4f0dba9aec/.pnp.cjs, it contains a large object literal that slows down the parse time. In an attempt to speed it up I stringified the object and parse it with Object literal: https://github.com/yarnpkg/berry/blob/fa346144fbcd783a1c77ab58fbe52cd796fa1f52/.pnp-object.cjs
Yeah, I have that as a note in the subsystem section |
Update: We were able to speed up parsing by using a multiline string literal instead of a template literal yarnpkg/berry#3977 |
Can we go ahead and close this issue? |
The reported issue (which most likely belongs in the V8 issue tracker and not here) is still valid, V8 is slower at parsing template literals without placeholders than string literals. Somehow V8 is also faster at parsing object literals than template literals which is odd ( |
If the issue still exists in v19.x/canary, please open a ticket at https://bugs.chromium.org/p/v8/issues/list |
Version
Platform
Subsystem
Though most likely deps/V8
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
The amount of time it takes to compile should ideally be the same.
What do you see instead?
Compiling the template literal is significantly slower
Additional information
No response
The text was updated successfully, but these errors were encountered: