webcomponentsjs icon indicating copy to clipboard operation
webcomponentsjs copied to clipboard

Causes firefox to hang while loading

Open shadowmint opened this issue 12 years ago • 35 comments

In firefox the terminal logs:

mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the    
object with the correct initial [[Prototype]] value using Object.create

As webcomponents.js loads it causes the browser to temporarily hang even when the tab is not active.

Performance log

perf

NB. This is a carry over issue from platform.js that was a performance regression from 0.4.0 that never got addressed.

shadowmint avatar Nov 26 '14 09:11 shadowmint

+1 I'm seeing the same issue in Firefox however I'm not sure it's directly related to the mutation of the prototypes.

Similar issue in Topeka app (polymer) and was closed as a non issue by the looks https://github.com/Polymer/topeka/issues/6

ghost avatar Dec 04 '14 18:12 ghost

+1

Also Firefox performance is horrible.. related to mutating the prototype?

nomego avatar Dec 15 '14 10:12 nomego

I guess, webcomponents is a platform independent library, You must solve this kind of problem. I am using requirejs with webcomponents and because of this performance issue, I am getting timeout error from requirejs. I request you to solve this bug and show love for Firefox ;)

deepaksisodiya avatar Jan 05 '15 16:01 deepaksisodiya

+1

neshkatrapati avatar Jan 28 '15 18:01 neshkatrapati

fyi, mutating the prototype is unavoidable, and has been there for as long as the polyfill has existed, so is unlikely to be related. Once Firefox implements Custom Elements and Shadow DOM natively, performance will be much better. Until then, you may have luck with webcomponents-lite.js, which doesn't include the (very expensive) Shadow DOM polyfill.

edit: and Mozilla is working on CE and SD. See post: https://hacks.mozilla.org/2014/12/mozilla-and-web-components/

jmesserly avatar Jan 28 '15 19:01 jmesserly

I hope FF will have native support soon, because current polyfills are extremely slow. Even IE is faster... I had to use a nasty workaround to display many elements on page. https://github.com/Polymer/polymer/issues/952

Mikanoshi avatar Jan 30 '15 18:01 Mikanoshi

@garlicnation why have you closed this? It is still unresolved.

shadowmint avatar Jan 31 '15 01:01 shadowmint

@shadowmint -- if you can provide more concrete info about the problem, we can take a look. I'm not sure what action to take from just looking at the perf screenshot (it looks like minified, so it doesn't provide any information like stack trace). If the culprit is ShadowDOM polyfill, there isn't much we can do until Firefox has native support. (If you're using Polymer, they are hard at work on the 0.8 branch, which will at least not depend so heavily on SD polyfill)

jmesserly avatar Jan 31 '15 01:01 jmesserly

more concrete info?

Firefox hangs all tabs when you open a page with a component on it using this polyfill.

What would you like me to provide? A codepen example? I can do that if it will help.

On Saturday, January 31, 2015, John Messerly [email protected] wrote:

@shadowmint https://github.com/shadowmint -- if you can provide more concrete info about the problem, we can take a look. I'm not sure what action to take from just looking at the perf screenshot (it looks like minified, so it doesn't provide any information like stack trace). If the culprit is ShadowDOM polyfill, there isn't much we can do until Firefox has native support. (If you're using Polymer, they are hard at work on the 0.8 branch, which will at least not depend so heavily on SD polyfill)

— Reply to this email directly or view it on GitHub https://github.com/webcomponents/webcomponentsjs/issues/75#issuecomment-72298719 .

shadowmint avatar Jan 31 '15 06:01 shadowmint

I closed the wrong issue when working on a related one. When debugging another SD bug my laptop was pegged at 100% cpu for the multi-second pageload time.

I think this is caused by changes in firefox, not the SD polyfill, but I'm investigating further to determine a root cause.

@shadowmint a codepen example would be great!

garlicnation avatar Jan 31 '15 17:01 garlicnation

Here's an example pen: http://codepen.io/shadowmint/embed/wCceK/

It may seem to open 'ok' in firefox, but watch what happens when you hit reload. The entire browser actually hangs during the load; opening firebug makes this even more obvious, but firebug always makes everything +50% slower anyway.

As the number of component instances increases, you'll experience the joy of bitbucket, where one of your tabs which is open entirely destroys the browser.

Just cut and paste a bunch of <hello-header id="copy2"></hello-header> into the html section of the pen to see it happen live.

fwiw notice both that this is using 0.5.3, not 0.5.4, but there's no meaningful difference in terms of performance, and that if you use webcomponents-lite.js this isn't an issue, but that's because using lite doesn't have a shadowdom, so the component code fails to load entirely.

ie. tldr; Could well be the shadowdom polyfil on firefox causing the issue, but you can't actually use components without it, so.... /shrug

shadowmint avatar Feb 01 '15 03:02 shadowmint

This is how you hang FF :) http://codepen.io/Mikanoshi/pen/jEGVOj

ShadowDOM polyfill is just too slow, same code in browsers with native WebComponents support takes 1-2 seconds.

Mikanoshi avatar Feb 02 '15 13:02 Mikanoshi

@Mikanoshi yup, that one is unfortunately not fixable though. If using SD polyfill, the best idea is to avoid creating a huge DOM. Something like https://github.com/Polymer/core-list which can load nodes on demand.

I did a lot of research on a faster SD polyfill, and it looks like it might be possible in Firefox/IE, but unfortunately that approach can't work on Safari because of a bug. So you'd need a special minifier, and most people didn't like that idea.

jmesserly avatar Feb 02 '15 17:02 jmesserly

IE is not a huge loss :) Safari? Who needs Safari. I'll just add a disclaimer that FF is slow with this site. I have ~500 paper-inputs divided into 15 core-pages, they are loaded dynamically, so only 20-40 polymer elements are on page at the same time, but performance is still bad.

Loading time is not the biggest problem, polymer elements are doing something in a loop, that makes everything on the page stutter, it's very noticeable during transitions (try slider in my codepen example).

Mikanoshi avatar Feb 02 '15 17:02 Mikanoshi

@Mikanoshi fyi Polymer 0.8-preview only depends on webcomponents-lite.js so that will hopefully make your experience better in the future :)

jmesserly avatar Feb 02 '15 18:02 jmesserly

@jmesserly Lite doesn't have ShadowDOM, but all polymer elements are based on templates, so it will be a very distant future :)

Mikanoshi avatar Feb 02 '15 18:02 Mikanoshi

Confirmed that this behavior is the same with 0.5.3 and 0.5.4 and is the same in past and current firefoxes.

With that said...

The ShadowDom polyfill will definitely be unnecessary with 0.8, and it will be clear how to upgrade existing elements.

garlicnation avatar Feb 02 '15 18:02 garlicnation

Is FF team not going to add native support? What are they waiting for?

Mikanoshi avatar Feb 02 '15 20:02 Mikanoshi

they are working on it https://hacks.mozilla.org/2014/12/mozilla-and-web-components/ bug tree for web components https://bugzilla.mozilla.org/showdependencytree.cgi?id=811542

you can actually go into about:config in firefox and enable "dom.webcomponents.enabled" flag. That makes APIs like createShadowRoot work. edit: document.registerElement too :)

jmesserly avatar Feb 02 '15 21:02 jmesserly

That flag breaks all polymer sites completely.

Mikanoshi avatar Feb 02 '15 21:02 Mikanoshi