shadydom icon indicating copy to clipboard operation
shadydom copied to clipboard

How performant is shadydom intended (esp. in IE11)?

Open mattdsteele opened this issue 9 years ago • 4 comments

For context: I'm interested in converting our company's component library (current a set of AngularJS 1.x components) to Web Components. We'd target IE11 + evergreens. Most of our clients are on IE11.

While doing some benchmarking I've found substantial performance hits when rendering web components, particularly in IE11. Slower than AngularJS 1.x, even. It appears that the use of shadydom is the main culprit here.

Here's a few Webpackbins wherein I'm testing the load time to create 1,000 elements with various frameworks:

Framework URL IE11 FF Chrome Safari TP
Vanilla (CE polyfill) https://www.webpackbin.com/bins/-KkwOSiqE_qryb75H6wo 921 179 190 169
Vanilla (CE + SD polyfills) https://www.webpackbin.com/bins/-Kkvn4HQpVPJJCrKn0b6 2800 428 184 174
Vue (dev mode) https://www.webpackbin.com/bins/-KkqHt9FOCoXV_qc7q_w 620 502 204 269
AngularJS https://www.webpackbin.com/bins/-KkqLUTVDarHnAbziblD 608 445 263 271

(Note: Webpackbin doesn't work in IE11, so I had to download the bins and npm start them locally)

It seems surprising that including shadydom would impact element creation in IE as much as it appears to. I haven't dug into it much, but I see big MutationObserver and DOM operations in the timeline.

So, is this expected performance with polyfilled browsers? Do these tests seem reasonable? Seeing performance like this makes it unlikely that we could move forward building atop web components. A 50% slowdown is one thing but a 500% slowdown is another 😶

/ref https://github.com/skatejs/web-components/issues/47

mattdsteele avatar May 24 '17 22:05 mattdsteele

Thanks for posting these benchmarks. We'll have to take a look before offering concrete feedback. In general, obviously we've endeavored to make the performance of Shady DOM as good as we can, and the numbers here don't match what we've seen in internal testing. It's possible this exact benchmark is hitting a slow path that isn't common when the polyfill is used with Polymer (where it has been most heavily tested). Will update this with more info soon...

sorvell avatar May 24 '17 23:05 sorvell

@sorvell Thanks. Y'all are doing yeoman's work here, and the product you've built already is 💯 . It's only because of your work that we can even consider using the platform!

For a bit more context, we were looking to use this in conjunction with SkateJS; and have a few additional benchmarks on the Issue I linked above. Similar kinds of results.

mattdsteele avatar May 25 '17 03:05 mattdsteele

Just a quick update. I've spent a bit of time looking at Vanilla (CE + SD polyfills) in IE11 and am seeing similar performance issues. We have a branch that should be landing soon which makes this test ~35% faster.

I think there's definitely more room for improvement and will be looking more at optimizing (1) setting innerHTML, (2) making sure the dom insertion code does as little as possible, (3) looking at trade offs between 2 ways of accessing native tree data (currently a TreeWalker is used, but it's also possible at least on some platforms to use native getters/setters).

Couple of things to mention: (a) it's better to load shadydom before customelements. This shouldn't change perf but makes connectedCallback less spammy, (b) it's important to test with any developer tools closed as this significantly affects performance.

sorvell avatar May 25 '17 23:05 sorvell

That's great to hear, @sorvell. You guys are doing awesome work :)

currently a TreeWalker is used, but it's also possible at least on some platforms to use native getters/setters

I remember in doing some micro-optimisations awhile back and using a TreeWalker was slower than a recursive function in IE (could have been older than 11, though). Just have to make the call-stack trade-off for it.

treshugart avatar May 26 '17 04:05 treshugart