Skip to content
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

perf: more precise check for < or > in mustacheTag #2213

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

jasonlyu123
Copy link
Member

Part of #2179

The reproduction of #2179 has a large HTML without any moustache or control flow blocks. So, the lastIndexOf check has to search through nearly the entire template part before the start position in every start tag/ end tag. But we only need to check the HTML's last "Content" part before the < or >. This will make the lastIndexOf checking way shorter string. Is there any other part we might need to check?

The perf difference in most files I tested is around ±10%, and most are within 1 ms, so it's not a big difference, even if it is slightly slower in some cases. But In the reproduction, the preprocess went from nearly 1000ms to 10ms.

I only apply the optimization to HTML content because attribute value might have whitespace. The scanner would treat it as a whitespace between attributes. For example,

<button on:click={() => {}} />

The scanner might parse it as on:click={(), = {}}. We might need a proper js/ts parser or scanner to know when the attribute ends. It can be more expensive since we need to check for every attribute with a js expression and can't lazily check only when there is a >. This is also part of the reason #2155 is a bit hard to fix.

@dummdidumm dummdidumm merged commit f1477a7 into sveltejs:master Nov 24, 2023
2 checks passed
@jasonlyu123 jasonlyu123 deleted the perf-large-html branch November 24, 2023 08:05
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.

2 participants