3 ms·
Indeed, DOM performance is often the real bottleneck. In Cappuccino we go to great lengths to avoid touching the DOM wherever possible. Views (which wrap DOM e
by tlrobinson 18y ago
Indeed, DOM performance is often the real bottleneck.
In Cappuccino we go to great lengths to avoid touching the DOM wherever possible. Views (which wrap DOM elements) keep track of their position and size, so we never have to ask the DOM. We defer DOM manipulations to the end of each "run loop" where we coalesce them, removing redundant operations.
The overhead of this bookkeeping (which is reduced by increase JS engine performance) is less than the overhead of extra DOM operations, so it's worth it.
We're already seeing other frameworks adopt some of these practices.
- gruseom 18y agoWe defer DOM manipulations to the end of each "run loop" where we coalesce them, removing redundant operations That's very interesting. Can you give examples of redundant operations that you coalesce? I'm wondering if this approach might help in my case. I'm frequently repositioning/resizing thousands of little divs. Any suggestions?
- tlrobinson 18y agoI'm not the expert on this among us, but from what I understand there are situations where changing one thing causes something else to change and so forth. The specific operations we coalesce are appending nodes, removing nodes, setting the position and setting the size. Are you changing the position of the divs multiple times per "event" (i.e. mouse/keyboard event, etc) or just very frequently on separate events? No idea how well this would work, but maybe you could have a timeout fire N times per second (5, 10, 15, 30?) and update the DOM positions then? Though with thousands of divs I don't know if that will help. What are all these divs? Are they simple enough they could be drawn with Canvas?
- gruseom 18y agoAre you changing the position of the divs multiple times per "event" (i.e. mouse/keyboard event, etc) or just very frequently on separate events? Very frequently on separate events. What are all these divs? The cells of a spreadsheet. (The pos/size resets happen as the user scrolls or does something resizey. Oh, and the content of the divs changes under these conditions too.) Are they simple enough they could be drawn with Canvas? They're about as simple as you could get (at least before you add in formatting and all that). I never considered Canvas as an option - do you recommend trying it? We might not need to do anything, since the deterioration in FF3 is already getting better with the next release of FF (Shiretoko), though not as good as FF2. On the other hand, performance of this particular UI is critical to its user-acceptance, and if there's something we can do to get significant improvement I'd probably go for it.