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(): rm runtime RegExp usages #9802
base: master
Are you sure you want to change the base?
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Build Stats
|
ffcc051
to
821278f
Compare
@@ -1,3 +1,6 @@ | |||
/** | |||
* Do not use in runtime | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is already used at runtime during svg parsing.
Which is the concept you wanted to add here? to do not add it in loops?
I think this change is fine, we moved out regexp from always-allocated to runtime-allocated by choice, we should remind it when we roll it back, if that hurts performance is fine. I need to understand what you mean when you say deoptmized code and use of regexp, deoptimization is usually when the v8 needs to rollback to sort of code parsing rather than compiled, is that what you mean? Please attach before/after flamegraph for reference |
new RegExp(`${filteredGroups.join(' ?')} ?$`), | ||
'' | ||
); | ||
match = match.slice(value ? value.length : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the changes to the path parsing code please either add a very detailed explanation or let's not do them.
if (!paramArr) { | ||
break; | ||
} | ||
// ignore undefined match groups | ||
const filteredGroups = paramArr.filter((g) => g); | ||
const filteredGroups = paramArr.filter(Boolean); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This equal to call Boolean as Boolean(g, index, paramArr)
this is usually suggested to avoid, i would avoid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid filter(Boolean)
also because from TS 5.5 it will be able to automatically type narrow .filter(g => !!g)
to defined values, but .filter(Boolean)
won't work
Description
During a perf profiling I noticed that regexp creation was showing up due to use of
parsePath
so I looked into the code found deoptimized code and deoptimized use of regexp.Therefore, I moved all regexp creation from runtime to const values and simplified a bit of
parsePath
In Action