Sure, it is expensive but it's developer's call whether and when to
use, isn't it?
Good point. Trying to discourage developers from doing something that will hose their performance without them realizing it is nice, but completely preventing them from writing code they way they want is possibly going too far. This is something we've been discussing for a while. Here's another thread with some more context:
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mi...@dartlang.org, Tom
How does that work under the covers? The underlying library is still reading node.style.offsetWidth, which is a synchronous operation. How does using a future prevent the browser from stopping the world to do reflows/repaints and calculations? This seems like a synchronous operation unnecessarily wrapped in an async control flow (unless I misunderstand something, which is totally possible).
Jay Young
unread,
Mar 18, 2012, 12:06:07 PM3/18/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mi...@dartlang.org, Tom
On Sunday, March 18, 2012 12:04:50 PM UTC-4, Jay Young wrote:
... The underlying library is still reading node.style.offsetWidth ...
Sorry, meant "element.offsetWidth".
Justin Fagnani
unread,
Mar 19, 2012, 1:44:05 AM3/19/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jay Young, mi...@dartlang.org, Tom
You can check out the source yourself, it's in html_frog.dart which is now conveniently shown in the editor (I love that feature).
The implementation adds each measurement request to a queue and evaluates all the measurements at the end of the current event loop. So while the calls to element.offset* are synchronous and do trigger a layout, all the calls generated by Element.rect() are batched together.
-Justin
Jay Young
unread,
Mar 19, 2012, 1:50:15 AM3/19/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mi...@dartlang.org, Jay Young, Tom
Ah hah. Brilliant! I tried looking for the implementation but couldn't find it (using an old version of the editor, I guess). Thanks.