Live data from Hacker News

How Bad is DOM Interaction Really?

andyshora.com

21–30 of 38 posts

Re: How Bad is DOM Interaction Really?

#22
post #2

After 10+ years as a performance leaning C++ desktop app developer I'm looking for any and all tips to make JavaScript (jQuery too) work in perceivably faster ways. I'm use to threading database calls, using message queues, and views updating themselves from caches. It’s a new world for me and feels somewhat like a step backwards. Here I come html5!

try angular JS for self updating views.

Re: How Bad is DOM Interaction Really?

#23

Earlier quoted context omitted.

Also, the code doesn't call into DOM directly but uses jQuery .html() for "reading" and .html(Math.random()) for "writing". The case is extremely misrepresented indeed.

The DOM is a failed institution trying to grab on the the ledge before it falls into the abyss. W3C should be disbanded and HTML5 abandoned. JavaScript and it's ilk should be boycotted by users as well. This kind of complexity should exist on the server, not in the browser. I understand that people want to run complex apps in the browser. It's a bad idea in general but where it's needed, it should be PLATFORM DEPENDE…

I'm trying to figure out if you're being sarcastic.

Re: How Bad is DOM Interaction Really?

#24

Earlier quoted context omitted.

Also, the code doesn't call into DOM directly but uses jQuery .html() for "reading" and .html(Math.random()) for "writing". The case is extremely misrepresented indeed.

The DOM is a failed institution trying to grab on the the ledge before it falls into the abyss. W3C should be disbanded and HTML5 abandoned. JavaScript and it's ilk should be boycotted by users as well. This kind of complexity should exist on the server, not in the browser. I understand that people want to run complex apps in the browser. It's a bad idea in general but where it's needed, it should be PLATFORM DEPENDE…

WTF is this? I don't even know where to begin with this crackpot of a post. You suggested nothing of value and just spout a bunch of FUD.

To your friends that agree with you from 2009, use `querySelectorAll` for a non-live NodeList, assuming he has kept up with JS actually having evolved and converging on standards.

I bet you flip your lid, too, to learn your server-side-only dystopia is running on top of JS (Node) services.

Re: How Bad is DOM Interaction Really?

#25

Earlier quoted context omitted.

Also, the code doesn't call into DOM directly but uses jQuery .html() for "reading" and .html(Math.random()) for "writing". The case is extremely misrepresented indeed.

The DOM is a failed institution trying to grab on the the ledge before it falls into the abyss. W3C should be disbanded and HTML5 abandoned. JavaScript and it's ilk should be boycotted by users as well. This kind of complexity should exist on the server, not in the browser. I understand that people want to run complex apps in the browser. It's a bad idea in general but where it's needed, it should be PLATFORM DEPENDE…

Yes and no. The choices are: (a) build a dumb terminal, or (b) build a platform for distributed applications. Currently, we have a dumb terminal with some programming features bolted onto the side. All kinds of concerns are mixed together. For example, portability and security of code execution are must be maintained by the Javascript implementation, whereas the only sensible way to do this is to use the VMM to sandbox code, then use a non-security-critical portability layer that can optimize some portable code as aggressively and unsafely as you like (not sure if this is what you're alluding to with your platform-dependent remark).

Sans the VMM part, which I only thought of a few years ago, I told people all of this (that once you commit to programming on the web you need a REAL programming platform) years ago, and was dismissed. Now that it's been half-done with asm.js, webgl, websockets etc being jammed in alongside all the dumb terminal concepts as well as all the horrible previous attempts to mix programming in (e.g. Javascript and the DOM), we're unlikely to get all the way there, because it will be "good enough".

Re: How Bad is DOM Interaction Really?

#26

Earlier quoted context omitted.

The DOM is a failed institution trying to grab on the the ledge before it falls into the abyss. W3C should be disbanded and HTML5 abandoned. JavaScript and it's ilk should be boycotted by users as well. This kind of complexity should exist on the server, not in the browser. I understand that people want to run complex apps in the browser. It's a bad idea in general but where it's needed, it should be PLATFORM DEPENDE…

WTF is this? I don't even know where to begin with this crackpot of a post. You suggested nothing of value and just spout a bunch of FUD. To your friends that agree with you from 2009, use `querySelectorAll` for a non-live NodeList, assuming he has kept up with JS actually having evolved and converging on standards. I bet you flip your lid, too, to learn your server-side-only dystopia is running on top of JS (Node) s…

I covered JS...

You have nowhere to begin because I'm absolutely right. The DOM is klausterfokken.

Re: How Bad is DOM Interaction Really?

#27

Earlier quoted context omitted.

The DOM is a failed institution trying to grab on the the ledge before it falls into the abyss. W3C should be disbanded and HTML5 abandoned. JavaScript and it's ilk should be boycotted by users as well. This kind of complexity should exist on the server, not in the browser. I understand that people want to run complex apps in the browser. It's a bad idea in general but where it's needed, it should be PLATFORM DEPENDE…

WTF is this? I don't even know where to begin with this crackpot of a post. You suggested nothing of value and just spout a bunch of FUD. To your friends that agree with you from 2009, use `querySelectorAll` for a non-live NodeList, assuming he has kept up with JS actually having evolved and converging on standards. I bet you flip your lid, too, to learn your server-side-only dystopia is running on top of JS (Node) s…

[deleted]

Re: How Bad is DOM Interaction Really?

#28

No discussion of repaint and reflow? You can't leave a discussion of those out when talking about the cost of DOM manipulation. You absolutely can touch the DOM, but should do so through and interface that manages or eliminates repaint and reflow.

I have same feeling, Making single frame of JS code to run fast is cool and dandy, but eventually browser will have to make freeze and do reflow+repaint. Eventually it will make profiling harder, think about caching .offsetHeight etc. properties. It does decrease script execution time, but it does not make your app to work faster.

The important trick to know is, don't mix DOM modification with DOM measurement. Measuring the DOM is what triggers the DOM modification queue to get flushed.

if you do something like

   $('a').each(function(k,e){
      $(e).append('' ...);
      var width = $(e).width()
      // do something with the width;
   }
If you have code like the above, it is going to cause a repaint on each iteration. If you unroll it into three separate loops, one that does dom modification, one that does dom measurement, and another that does modification, then you will drop the number of repaints from potentially 100s to just 2.

Re: How Bad is DOM Interaction Really?

#29

Earlier quoted context omitted.

Also, the code doesn't call into DOM directly but uses jQuery .html() for "reading" and .html(Math.random()) for "writing". The case is extremely misrepresented indeed.

The DOM is a failed institution trying to grab on the the ledge before it falls into the abyss. W3C should be disbanded and HTML5 abandoned. JavaScript and it's ilk should be boycotted by users as well. This kind of complexity should exist on the server, not in the browser. I understand that people want to run complex apps in the browser. It's a bad idea in general but where it's needed, it should be PLATFORM DEPENDE…

To the Hellbanned user who replied: Well look what "good enough" has brought us now on the web. Constant security issues and a outbreak of for profit blackhats.

Re: How Bad is DOM Interaction Really?

#30
post #10

The real hits to performance do not come from "I did X writes" or "I did Y reads", but rather from situations such as "I did X writes interleaved with Y reads, which caused Z reflows". Or "I needed to update a tiny part of the screen but triggered a full-page repaint". Or "I'm doing complex animation X, but am not triggering hardware acceleration." Reflows are very expensive. So are repaints. Chrome dev tools will al…

There are a couple of excellent videos on developers.google.com that dig into this a little bit. I highly recommend watching the following video where two Google developers analyze some real world sites and fix the performance issues: http://www.youtube.com/watch?v=z0_jD8nO5Zw There are some great tips in it.
Post reply on HN