Re: [whatwg/dom] Add NodeList.setAttributes (#895)

Thanks for everyone's contributions to this discussion!

> How is this different than, or perhaps, could this be implemented using, the "Template Instantiation" proposal?

@mfreed7 @yuzhe-han Thanks, I hadn't seen that before! The template proposal looks very promising and useful. I think many optimizations for batch changes can and should be made with this approach, and so I agree that there is some common functionality. But the proposal assumes that developers switch to this templating approach of manipulating the DOM (via the "Part" and "*Part" objects), which in my view is independent from this proposal. I don't think the ability to use batched changes should require developers to interact with the DOM via the templating and "*Part" approach.

> How much faster might a native "bulk" API be, as compared to the current practice of one-at-a-time? This would likely require some prototyping to measure. There would clearly be some benefit, as the round-trips through the JS bindings layer would be eliminated. But these are already highly optimized, so it's unclear how much time would be saved.

I don't know the answer to this question. I know that the loop over setAttribute is often the majority of the render time in each frame of a data visualization (often over 20ms in real world applications that update only a handful of attributes, but on thousands of nodes), and my intuition is that a low level loop setting the attribute values within the browser would not take that long. But I agree that this should be prototyped. I haven't worked on Chrome directly, so if you want me to do this prototyping, it will take me some time to ramp up. I'm willing to do this work, but am quite busy until the Christmas break. I'm also joining Google again for full time in January, so I will have more time for this work then.

>Is this a single API that supports: multiple elements? properties? attributes? Or are there separate APIs for all of the above?

What I'm proposing is that the API supports multiple elements. In my view, this is clearly the major bottleneck: there is always a finite set of attributes that you are setting, but the number of elements is unbounded. I understand if you want to provide a more systematic solution that encompasses other requests, and I agree with @LeaVerou that the readability can improve if we could manipulate multiple attributes. But it's not the focus of this proposal.

>Is there some sort of ordering of assignments that is preserved?

No, I'd say the order is irrelevant.

I also like @LeaVerou's comment on the benefits of the static method. `Element.setAttributes(elements, attributeValues)` would be wonderful.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/895#issuecomment-727091633

Received on Friday, 13 November 2020 23:59:08 UTC