[webkit-dev] An idea to improve render performance by caching image-data's intrinsic size

Johnny Ding jnd at google.com
Mon Apr 13 12:16:22 PDT 2009

Hi Dave, Maciej

Thanks very much for quick response and detail explanation!  It did convince
me.I will try to add log like Maciej suggested to see how common the
situation is.

On Sat, Apr 11, 2009 at 4:45 AM, Maciej Stachowiak <mjs at apple.com> wrote:

> On Apr 10, 2009, at 6:51 AM, Johnny Ding wrote:
> Hi all,
> I have an idea about caching image's intrinsic size to improve render
> performance.
> We know the dynamic size change will cause the page re-layout when
> rendering HTML pages. It hurts render performance. The size change of images
> are usual cases for this issue.  In HTML pages,  The <img> tag might not be
> specified width and height, or only has specified width/height.  In this
> case, the img's render size will be calculated based on the intrinsic size
> of image-data.
> Before getting the actual image data, WebKit will use default intrinsic
> value (now is width:0 / height:0) to calculate the size of renderImage
> object,  aftering receiving the real image data, the intrinsic size of
> renderImage object will be changed,  the "imageChanged" method will be
> called and the layout around the renderImage could re-layout.  If the
> renderImage object is nested in couple of render containers, the area which
> need to re-layout could be big and even the whole page could need to
> re-layout.
> My idea is after first time requiring a image data, we use a map to cache
> the intrinsic size of the image data, such as
> http:///www.a.com/1.jpg    200*160  ... (additional properties)
> http:///www.b.com/2.jpg    160*200  ...
> Then next time one renderImage is created, we use its url of image data to
> look up the previous recorded size info and set it as default intrinsic
> value. I know the real intrinsic size of some images could be changed, but
> so far we don't care because the value we cached is only used as default
> value or you can say it's potential value.  Once we get real size from
> outside world, the right value will be applied. Actually in most of times,
> the previous recored intrinsic size is the real sintrinsic size.  Since we
> use right intrinsic size to calculate the size of renderImage objects from
> first time,  when real imag datas are coming, we might not need to do lots
> of re-layout action. It should improve the whole render performace of
> WebKit.
> We've discussed ideas along these lines before. It seems unlikely to me
> that a size cache would be much more effective than the actual data cache.
> And if we have cached data for the image, cached size info does not improve
> things. One way to test this hypothesis: add logging to determine how often
> in a typical browsing session you load an image that has been previously
> loaded, but that is not in the cache. This is the only case that will be
> helped, so it is good to know how common it is. Then we can do some
> estimation to see how big a "size cache" would likely be needed to catch
> these cases.
> Regards,
> Maciej

Best Regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090414/879f23ca/attachment.html>

More information about the webkit-dev mailing list