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(): rm runtime RegExp usages #9802

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

perf(): rm runtime RegExp usages #9802

wants to merge 2 commits into from

Conversation

ShaMan123
Copy link
Contributor

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

Copy link

codesandbox bot commented Apr 17, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

github-actions bot commented Apr 17, 2024

Build Stats

file / KB (diff) bundled minified
fabric 915.350 (-0.083) 305.619 (-0.019)

@@ -1,3 +1,6 @@
/**
* Do not use in runtime
*/
Copy link
Member

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?

@asturur
Copy link
Member

asturur commented Apr 17, 2024

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);
Copy link
Member

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);
Copy link
Member

@asturur asturur Apr 17, 2024

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

Copy link
Contributor

@jiayihu jiayihu May 4, 2024

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

microsoft/TypeScript#50387 (comment)

@asturur asturur marked this pull request as draft April 25, 2024 14:45
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.

None yet

3 participants