What is a reflow?

Reflow is the process by which the geometry of the layout engine’s formatting objects are computed.  Last week, I was searching around and stumbled on these really cool visuals of what a reflow looks like.  If you’re a visual person, you will dig these:

Reflow of Mozilla.org:

[googlevideo=http://video.google.com/googleplayer.swf?docid=1020647662203348823]

Reflow of Google.co.jp:

[googlevideo=http://video.google.com/googleplayer.swf?docid=-1471976166301235697]

Reflow of Wikipedia:

[googlevideo=http://video.google.com/googleplayer.swf?docid=-5863446593724321515]

If you produced these, kudos!  If you know how to produce such things, please drop a note!


Update:

Satoshi Ueyama is the author of this cool demo.  He sent Gen a note on how he did it:

First, he builds Mozilla so that the layout portions (nsIFrame::SetRect, nsIFrame::SetSize, nsIFrame;;SetPosition, PresShell::DoReflow, etc) are set to output to the log file.

He then gives an example of the log of each of the frame movements from Reflow:

{"event": "MoveFrame", "frame": {"address": "0x04FE41A8", "type":
"TextFrame", "content": {"address": "0x05014150", "type": "other"},
"rect": {"x": 0, "y": 0, "w": 0, "h": 0}}},
{"event": "MoveFrame", "frame": {"address": "0x04FE41A8", "type":
"TextFrame", "content": {"address": "0x05014150", "type": "other"},
"rect": {"x": 0, "y": 0, "w": 0, "h": 0}}},

Here is an example of dump from the termination of the tree structure.

{"event": "FinishReflow", frame:
 {"address": "0x04FE3E28", "type": "ViewportFrame", "content": null,
"children":[
     {"address": "0x04FE4000", "type": "ScrollFrame", "content":
{"address": "0x04FD4858", "type": "element", "tagName": "HTML"},
"children":[
         {"address": "0x04FE43EC", "type": "ScrollbarFrame",
"content": {"address": "0x04FFEFF8", "type": "element", "tagName":
"scrollbar"}, "children":[
             {"address": "0x04FE4578", "type": "BoxFrame", "content":
{"address": "0x04FFE0F8", "type": "element", "tagName":
"xul:scrollbarbutton"} }
     ,
       {"address": "0x04FE47BC", "type": "sliderFrame", "content":
{"address": "0x04FFE278", "type": "element", "tagName": "xul:slider"},
"children":[
                 {"address": "0x05004E6C", "type": "BoxFrame",
"content": {"address": "0x050030E8", "type": "element", "tagName":
"xul:thumb"}, "children":[
                     {"address": "0x05004FDC", "type": "BoxFrame",
"content": {"address": "0x050013F0", "type": "element", "tagName":
"xul:gripper"} }
         ] }

He then makes the video animation (for Google Video he suggests Ruby+Ruby/SDL, for the video from Mozilla 24 he used C+++Direct3d.) As memory address is outputted to the log each frame can be distinct.

The behavior of each frame in chronological order is reproducible as the log has each frame’s memory. (For instance, in tracking the frame “address”:”0x04FE41A8″, you can reproduce that frame’s behavior chronologically.

UPDATE:

New links for the videos (thanks Gen!):

http://www.youtube.com/watch?v=nJtBUHyNBxs
http://www.youtube.com/watch?v=ZTnIxIA5KGw
http://www.youtube.com/watch?v=dndeRnzkJDU

This entry was posted in mozilla and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

34 Comments

  1. Dan
    Posted May 24, 2008 at 7:33 pm | Permalink

    Someone totally needs to make that into a Firefox extension.

  2. Posted May 24, 2008 at 8:28 pm | Permalink

    Wow. That’s awesome.

  3. Posted May 24, 2008 at 10:01 pm | Permalink

    That’s awesome. I second post #1

  4. Posted May 24, 2008 at 10:57 pm | Permalink

    Interesting that it’s reflowing the whole thing twice for mozilla.org and wikipedia, but *not* google.

  5. Posted May 24, 2008 at 11:31 pm | Permalink

    Woah, it’s awesome, seriously. Who made these? Any chance for higher resolution ones? Or even better an interactive thingie (1st post, further seconded.)

  6. Posted May 25, 2008 at 1:33 am | Permalink

    That is just spectacular. I am dying to find out who was responsible.

  7. Posted May 25, 2008 at 1:58 am | Permalink

    Wow, someone please add that to Firebug or WebDeveloper extension! I’d love to see how the reflow unfolds on my website and if there’d be anyway I could then optimise it for faster rendering.

  8. WizKid
    Posted May 25, 2008 at 3:06 am | Permalink

    glandium: I think that is because Mozilla and Wikipedia becomes larger then fit on screen so the scrollbar needs to be placed on the right. And therefor there is a second reflow.

  9. Anonymous
    Posted May 25, 2008 at 3:07 am | Permalink

    Maybe that is because google doesn’t use CSS?

  10. pufone
    Posted May 25, 2008 at 4:17 am | Permalink

    f this s, Opera draws pages as soon as data comes in, does not hide the layout until it’s fully generated.

  11. Anonymous
    Posted May 25, 2008 at 4:34 am | Permalink

    I think it’s animations related to this talk at Shibuya.js:
    http://video.google.com/videoplay?docid=4146973749385284875

    This seems to be the guy who made it:
    http://gyu.que.jp/sjs2007/

    Guessing it’s done in Processing, since he has some other stuff done in that too.

  12. David
    Posted May 25, 2008 at 5:58 am | Permalink

    Those are cool. A firefox extension would be pretty cool! :)

  13. Posted May 25, 2008 at 6:28 am | Permalink

    Interesting. I completely agree with Dan above… it’d be great if this were a Firefox extension.

  14. Boris
    Posted May 25, 2008 at 7:45 am | Permalink

    It looks like this animation captures all calls to SetRect/SetPosition/SetSize on frames or something along those lines. At least that’s what it looks like to me given how it’s handling the floats and the inline layout. Doing that from an extension would be quite difficult, actually, and any setup that _did_ do it would have a pretty hefty impact on layout performance.

  15. Posted May 25, 2008 at 7:50 am | Permalink

    Awesome visual demos. Thank you!

  16. Posted May 25, 2008 at 7:51 am | Permalink

    This is awesome, seeing the process slowed down and outlined like this. A firefox extension would be great!

  17. Bill
    Posted May 25, 2008 at 9:20 am | Permalink

    @16:
    You wouldn’t need to do it real time; you would just need to log the calls to those functions somewhere so that you can parse them and create an animation (that said it would still be difficult from an extension I think; you may want a custom build of the browser instead).

  18. Posted May 25, 2008 at 12:12 pm | Permalink

    Seeing as almost all pages have vertical scrolling, it seems like a sensible optimisation to render assuming a scrollbar first, and then if it isn’t required, to reflow.

    In fact I remember that Opera 6 or so always rendered with a scrollbar visible. At the time I assumed it was to avoid the content jumping around on sites where some pages have scrollbars and some don’t. But maybe it was an optimisation. Opera has always focused on speed more than the other browsers.

  19. Posted May 25, 2008 at 1:50 pm | Permalink

    I like it.

    That is all.
    (Apologies I’m not very tech savvy and there cannot make this comment more interesting)

  20. Posted May 25, 2008 at 5:27 pm | Permalink

    Looks cool! :)

  21. Posted May 25, 2008 at 9:53 pm | Permalink

    I like the pretty colors… Just kidding. Seriously, I AM a visual person, and I LOVE watching technical things like this unfold visually before me. Great videos, thanks a lot for sharing!

  22. baklavagirl
    Posted May 25, 2008 at 10:44 pm | Permalink

    Thanks. I don’t know much about computers but I really thought that was so cool.

  23. Posted May 26, 2008 at 1:13 pm | Permalink

    Check out Timelapse CSS by Mattew Buchanan:

    http://matthewbuchanan.name/post/33504871/timelapse-css

  24. Posted May 27, 2008 at 1:02 am | Permalink

    > Which makes you wonder why the entire mozilla
    > page needs to be reflown for that since it has
    > fixed margins.

    Wow, from 3 small, lo rez videos we already have a possible bug.

    Interesting how information presented in a new way helps us all understand a complex process.

    monk.e.boy

  25. Posted May 27, 2008 at 3:20 am | Permalink

    Doug- that was at our Mozilla 24 event, albeit in the Tokyo part of the event.

  26. Dave Newell
    Posted May 27, 2008 at 2:11 pm | Permalink

    That was a lot of good info.

    dave, http://www.thehistorybluff.com

  27. Posted May 27, 2008 at 9:02 pm | Permalink

    I can’t see anything? Sorry!

  28. Posted May 28, 2008 at 2:52 am | Permalink

    I want the tool that makes these animations, it would be SOOO helpfull when developing websites!

  29. Posted May 28, 2008 at 8:18 am | Permalink

    I might finally understand floats if that was an extension. :)

  30. Posted May 28, 2008 at 12:35 pm | Permalink

    awesome posts

    thanks dear

  31. Posted May 29, 2008 at 8:02 am | Permalink

    Fantastic rendering demonstration. Its only a matter of time before something like this gets pushed out into the open source domain.

  32. Boris
    Posted June 1, 2008 at 9:29 pm | Permalink

    Bill, you’d definitely need a custom build (not possible to hook into those layout guts from an extension). And I wasn’t talking about doing anything in realtime: just logging those function calls might be expensive enough to noticeably affect layout performance. Those functions are called a _lot_.

  33. Posted February 4, 2009 at 9:26 pm | Permalink

    Excellent! I didn’t get why on the first video (Mozilla.org reflow) it went over the whole thing two times?

  34. ese
    Posted March 20, 2009 at 10:28 pm | Permalink

    That is just insane!!! Fantastic demo, should totally be made into a extension.

21 Trackbacks

  1. [...] Layout Engine Geometry You may also want to browse: A Fascinating Constellation, Candy, Pervasive Visualisation,  [...]

  2. [...] were found by DougT somewhere on Google Video. There are others (such as Wikipedia) that he shows on his blog.. He (and [...]

  3. By Top Posts « WordPress.com on May 25, 2008 at 3:58 pm

    [...] What is a reflow? Reflow is the process by which the geometry of the layout engine’s formatting objects are computed.  Last week, [...] [...]

  4. By Un gaditano en Silicon Valley » » Reflow on May 25, 2008 at 9:26 pm

    [...] El vídeo muestra el modo en que gecko procesa la información del DOM y las hojas de estilo al montar una página tal y como la vemos. Las animaciones muestran como el motor renderiza la información de la página a visualizar conforme le va llegando y como cambios en la estructura de la misma (nuevas tablas o cambios en el CSS) afectan a determinadas partes de la visualización. Además de la wikipedia en japo, existen visualizaciones para google.co.jp y la página principal de mozilla. [...]

  5. By kann hier jemand Polnisch? - XHTMLforum on May 26, 2008 at 11:38 am

    [...] keiner Polnisch, aber dafür ist dies für denjenigen interessant, der sich mit mir fragt, was ein Reflow in Gecko ist. __________________ Ingo Chao :: satzansatz :: dolphin’s [...]

  6. By Giavasan » Special FX on May 26, 2008 at 1:20 pm

    [...] una pagina web a partire dai suoi componenti fondamentali, i frames. DougT ha raccolto sul suo blog tre video che mostrano in dettaglio i reflow di google.co.jp, mozilla.org e ja.wikipedia.org, ed è [...]

  7. By Create A Website » Blog Archive » Reflow on May 26, 2008 at 3:20 pm

    [...] across an article on “reflow”: the process by which the geometry of the layout engine’s formatting objects are [...]

  8. [...] um processo chamado reflow, da página do Google. Investiguei mais a fundo e achei um artigo no DougT’s Blog, com mais alguns [...]

  9. [...] ne sais pas comment on arrive à produire ce genre de vidéo, ni la source sur laquelle j’ai trouvé ces exemple d’ailleurs. A priori c’est une histoire de [...]

  10. [...] (via: dougt.wordpress.com) [...]

  11. [...] Via: Google Blogoscoped e Dougt [...]

  12. By ¿Cómo piensa un navegador? on May 27, 2008 at 2:22 pm

    [...] de la Wikipedia elemento a elemento. Dos vídeos más con reflows de Google y de Mozilla.org en dougt.wordpress.com/2008/05/24/what-is-a-reflow sin comentarios en: tecnología, software karma: 6 etiquetas: firefox, navegador, reflow votos [...]

  13. By Mobimeet - Reflows on May 27, 2008 at 10:40 pm

    [...] In any case, a couple of good examples cropped up on the net including this one below.  Check out this post for a couple [...]

  14. By » Reflow on May 28, 2008 at 1:36 am

    [...] dougT 的 Blog 裡面的回應裡有討論到,似乎是日本的 Gecko 所弄出來的 [...]

  15. By 形象化的reflow - 样式之美 on May 28, 2008 at 8:50 am

    [...] 现在,我们能形象地看到这个reflow是怎样的一个过程了(via:What is a reflow?),先看一下Mozilla的首页; 看不到点这里看,再看不到就用代理来看,再再看不了的话就邮件给我发文件给你。。 [...]

  16. By What is a reflow? « Science Notes on May 28, 2008 at 2:00 pm

    [...] What is a reflow? 2008 May 28, Wednesday, 18:00 — monado On Doug T.’s blog, you can learn about reflows: what is a reflow and how are they calculated? [...]

  17. By gregs » Blog Archive » Reflow on May 29, 2008 at 8:27 pm

    [...] more appropriately what is it? [...]

  18. [...] Have you ever heard of reflows in terms of browser rendering? I hadn’t but this short blog post has some neat videos of them in action. Check it out, let me know what you think. This entry [...]

  19. [...] What is a reflow? [...]

  20. [...] Ueyama-san, the programmer who made those 3D demos, is the same programmer who did those Gecko reflow videos (Japanese) that were widely blogged about and discussed at Doug Turner’s blog: What is a reflow? [...]

  21. [...] Last May, my colleague Doug Turner happened across some videos showing how the Gecko engine does reflow: What is a reflow? < DougT’s Blog [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>