window.getComputedStyle poor performance
See original GitHub issueI am currently in the process of bringing in some code written for the browser to nodejs which involves running window.getComputedStyle on a lot of elements. In the browser we are seeing times under 500ms where as with jsdom’s implementation of getComputedStyle our times are above 5000ms.
I created a sample that takes ~3000ms to execture in nodejs using jsdom@9.4.1, jquery@3.1.0 and xmldom@0.1.22
var jsdom = require('jsdom');
var window = jsdom.jsdom().defaultView;
var DOMParser = require('xmldom').DOMParser;
var jQuery = $ = require('jquery')(window);
var xml = '<span style="color: #fff;">test</span>';
var xmlDom = $(xml);
console.time('getComputedStyle');
for (var i = 0; i < 1000; i++) {
var cs = window.getComputedStyle(xmlDom[0]);
}
console.timeEnd('getComputedStyle');
And here is a jsfiddle to test in broswer which takes about ~0.5ms: https://jsfiddle.net/3dzLLf5x/
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
getComputedStyle local vs every time in function Performance
Is it better or worse to make the ComputedStyle a global variable? I strongly recommend avoiding actual global variables as much as possible....
Read more >getComputedStyle performance 20x worse than Safari for ...
Compare to Safari (Windows) Workaround: If the table's display style is set to "none" for the duration of the layout, Firefox's performance difference...
Read more >window.getComputedStyle performance - Prince forum
Although I doubt it's the cause of this performance issue, it looks like Prince is reloading the CSS files everytime the DOM reflows....
Read more >JavaScript Window getComputedStyle() Method - W3Schools
The getComputedStyle() method gets the computed CSS properties and values of an HTML element. The getComputedStyle() method returns a CSSStyleDeclaration object ...
Read more >How We Increased Our Plugin's Performance by 200%
What's more is that even when the getComputedStyle result was cached, it was still really slow. As it turns out, accessing the style...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Node.js 6.3.0, jsdom 9.4.1, Win 7. Simplified test code:
In the last Chrome for
about:blank
:@staramir / @vsemozhetbyt you can retry now using nwmatcher 1.4.0 the changes may be of help improving the performances. You will have to use both the VERBOSITY and LOGERRORS flags, setting them to
false
to mute both the exceptions and the console output.