-
-
Notifications
You must be signed in to change notification settings - Fork 926
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
[refactor] Performance improvement of updateStyle() #2985
Conversation
991a051
to
9bb0d98
Compare
@kfule Can you run the benchmarks in the browser using the internal test page in You can spin up any server you'd like in the repo's root and just open that page. Benchmark results will be printed in the web console. |
If it works as advertised, I also want to port it over to #2982, as that is the benchmark it's bottlenecked on most. |
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.
Approved modulo nit + in-browser benchmark run request.
@dead-claudia |
@dead-claudia SummaryIn Edge and Safari, the benchmark seems to have improved by about 10%. Apart from the unclear results in Firefox, performance seems to have improved in Edge and Safari. DetailsFirefox 132.0 (x64,win) (1st round, no improvements)PR's “mutate styles/properties” performance is about 102% vs. v2.2.9. results
Edge 130.0 (x64,win)PR's “mutate styles/properties” performance is about 114% vs. v2.2.9. results
The results of includes() are measured later.
safari 17.4(m2,macOS)PR's “mutate styles/properties” performance is about 108~111% vs. v2.2.9. results
The results of includes() are measured later.
Firefox 132.0 (x64,win) (2nd round)PR's “mutate styles/properties” performance is about 111~118% vs. v2.2.9. results
|
Also, Edit: I hosted the files on the server and access to them by client browser as a test, but the results did not seem much different than if I had opened it locally. |
@kfule To be clear, my Though...I decided to do a bit more reading, and turns out that the |
Sorry for dragging this out for so long. I just want to make sure we're getting it right the first time so we don't have to come back to it later. 😅 |
@dead-claudia Thanks for your detailed comments. I don't mind that it takes time to kindly review. So, there is no problem with if statements limited to custom properties, and there is room for performance improvement. If the change does not affect performance improvement, I would like to push it. Also, in case you're interested, I've tried other approaches and will share my findings.
|
This will improve the performance of “mutate styles/properties” and reduce the amount of code a little. Also, it turns out that the CSSStyleDeclaration interface also supports stuff like elem.style["font-size"] as well as the equivalent elem.style.fontSize. https://drafts.csswg.org/cssom/#dom-cssstyleproperties-dashed-attribute
9a36904
to
5d5e0e3
Compare
It may be better to add a set-get test for dashed properties (probably testable with current DOM mock), but the interoperability of dashed and camelCased properties may be handled separately from this PR . Edit: The flems above appears that different keys operate on the same property, so after setting with a new key, the old different key deletes the new value. |
@kfule Resolving this would almost certainly tank attribute setting performance. I'd be open to adding that to https://github.com/MithrilJS/docs as a thing to watch out for, but I'm highly skeptical a library fix is viable. |
@dead-claudia Thanks for approving. |
That's so strange, considering it worked only a week ago. |
@dead-claudia There appears to be a rule in the release branch ruleset that prohibit force pushes. |
@kfule Yes, but v2.2.9 was successfully published and nobody made any changes between then and now. That's what makes this so confusing. In any case, I've manually completed the process. |
This is a refactoring to improve the performance of
updateStyle()
.Description
In this PR,
style.setProperty()
inupdateStyle()
is used only when there is a dash "-" in the key. This seems to improve performance and reduce code size by eliminatingnormalizeKey()
andtoLowerCase()
.The benchmark "mutate styles/properties" on nodejs show about an over 50% improvement as follows.
results of `npm run perf`
before (v2.2.9)after ("mutate styles/properties" is improved)
I have not measured it precisely, butalso in real browsers the benchmark “mutate styles/properties” seems to show an improvement (about 10%?).(Edit) results in real browsers: #2985 (comment)
Motivation and Context
Following #2983, I backported the latest benchmark scripts to v1.1.7, measured and compared the benchmarks with v2, and found that the style-related benchmark "mutate styles/properties" were significantly slower. Even though the many fixes and enhancements merged into v2, its performance seemed too slow.
I checked the code and one of the major causes seemed to be the use of regular expressions and replacements (i.e.
normalizeKey()
andtoLowerCase()
) inupdateStyle()
to always usestyle.setProperty()
to support css vars.How Has This Been Tested?
npm run test
Types of changes
Checklist