set cssText: avoid serializing cssText when not needed#254
Merged
domenic merged 1 commit intojsdom:mainfrom Dec 8, 2025
Merged
set cssText: avoid serializing cssText when not needed#254domenic merged 1 commit intojsdom:mainfrom
domenic merged 1 commit intojsdom:mainfrom
Conversation
Contributor
|
I think this fix is already applied in another PR: |
Contributor
Author
Yes, I can confirm that both changes are applied there in the rewritten code. |
This was referenced Dec 4, 2025
domenic
approved these changes
Dec 8, 2025
Member
domenic
left a comment
There was a problem hiding this comment.
Let me approve this and do a release, while we continue working on the larger refactoring.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.