set cssText: avoid serializing cssText when not needed #254
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes jsdom/jsdom#3985, at least a big part of it.
During
set cssTextthe library callssetPropertymany times but wants to fire theonChangecallback only once at the end. That's what thethis._setInProgressfield is for. But despite_setInProgressbeingtrue, theget cssTextgetter is called many times: to get theoriginalText, and because of suboptimal order of conditions.This patch helps avoid these unneeded and expensive
get cssTextcalls. They are expensive because they serialize the AST structure to a string.I've been testing this on a little JSDOM benchmark script:
Before this PR, it takes 230ms to execute, after this PR it's 130ms, almost 2x improvement.
I think there are going to be even more optimization opportunities. If I remove the
div.style.cssTextassignment, the whole loop runs in 1ms.