-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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(SSR): remove slow regular expression for escapeHtml #12507
base: main
Are you sure you want to change the base?
perf(SSR): remove slow regular expression for escapeHtml #12507
Conversation
Creating an appropriate benchmark is quite complex. I attempted a slightly more complex one. During testing, 100 strings of lengths ranging from 3 to 100 are randomly generated, and they may or may not include characters that need escaping. As a comparison, I also added an implementation that uses regular expressions exclusively for the replacement: https://jsben.ch/uPxu5 In short, Vue's current implementation is consistently faster. |
@Justineo Thanks a lot, however it seems you named the function mistakenly, oops In https://jsben.ch/uPxu5, Then the result should be explained as "This PR is faster" |
I’m AFK right now, but what you said sounds possible. I’ll take a look when I get back. |
@ShuiRuTian Yes you are right. I've made an updated benchmark: https://jsben.ch/pbGau Some additional findings:
|
LGTM.
|
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-sfc
@vue/compiler-ssr
@vue/compiler-dom
@vue/runtime-core
@vue/reactivity
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Regular expression is slow, removing them in escapeHtml should make things faster
The perf result shows it's 2x~3x faster: https://jsbench.me/rqm4ehfndc/1
Ping @edison1105 @Justineo @bgoscinski, for you commented on another perf PR, so I guess you might also have interest in this one :)