- From: Mike Sherov <mike.sherov@gmail.com>
- Date: Wed, 14 Aug 2013 01:26:19 -0400
- To: Simon Pieters <simonp@opera.com>
- Cc: "www-style@w3.org" <www-style@w3.org>, François REMY <francois.remy.dev@outlook.com>
Mike Sherov Chief Technologist SNAP Interactive, Inc. | Ticker: STVI http://snap-interactive.com | http://ayi.com On Aug 13, 2013, at 3:30 PM, Simon Pieters <simonp@opera.com> wrote: > On Tue, 13 Aug 2013 20:02:53 +0200, François REMY <francois.remy.dev@outlook.com> wrote: > >>> While trying to use WebIDL's new [SameObject] and [NewObject] extended >>> attributes where applicable in CSSOM [1], I noticed that the GetStyleUtils >>> members return new objects each time but doing so is discouraged for >>> attributes [2]. I don't think it makes sense for these to return the same >>> object each time since that would mean having to keep the object live >>> which is probably quite expensive. >> >> Why? You don't actually have to "keep the object live", it's exactly similar to getComputedStyle(element) works (or element.currentStyle in IE, for what it's worth): the object is a sort of proxy and when you ask for a propery it returns from cache the value is up-to-date or modify the cache if it's not (or not anymore). It doesn't cost more than calling the getSomeStyle() function again and again every time. >> >> In fact, I would argue it's better because the issue if you outputs a static object is that you've to compute the value of every property straight when calling the function, while you can do so lazily per-property on demand with a live object. >> >> Thoughts? > > You're right. For some reason I thought getComputedStyle was static in implementations, but it's live in WebKit/Blink/Gecko/IE10: > > http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2448 > > So the spec needs to be fixed to say that getComputedStyle is live. > > This information also means that the GetStyleUtils can be changed back to attributes, and we can make them return the same live object each time. > > > getComputedStyle returns a new object each time even if it gets invoked with the same arguments in WebKit/Blink/Gecko, but not in IE10: > > http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2449 > > Does anyone have an opinion about which is better, or should I just go with the majority? Is getComputedStyle often invoked with the same arguments in a tight loop in the wild? jQuery used to call gCS in a tight loop (for animations). In fact, a recent optimization for Webkit I did passes the result around to avoid multiple lookups. The savings were significant. I can dig up my old perf results if you're interested. > > -- > Simon Pieters > Opera Software >
Received on Wednesday, 14 August 2013 05:26:51 UTC