Bug 74830 - Avoid instantiating ScrollAnimators when possible.
Summary: Avoid instantiating ScrollAnimators when possible.
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andreas Kling
Depends on:
Reported: 2011-12-18 18:16 PST by Andreas Kling
Modified: 2011-12-19 10:11 PST (History)
2 users (show)

See Also:

Proposed patch (1.58 KB, patch)
2011-12-18 18:25 PST, Andreas Kling
darin: review-
Details | Formatted Diff | Diff
Proposed patch v2 (1.74 KB, patch)
2011-12-19 09:38 PST, Andreas Kling
bdakin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kling 2011-12-18 18:16:11 PST
On the HTML5 spec page ( http://whatwg.org/c ), we instantiate 1683 ScrollAnimator objects, but only a single one is used.

Bytes Used	Count		Symbol Name
 420.75 KB       1.0%	1683	 	  WebCore::ScrollAnimator::create(WebCore::ScrollableArea*)
 420.75 KB       1.0%	1683	 	   WebCore::ScrollableArea::scrollAnimator() const
 420.25 KB       1.0%	1681	 	    WebCore::ScrollableArea::scrollToOffsetWithoutAnimation(WebCore::FloatPoint const&)
 420.25 KB       1.0%	1681	 	     WebCore::RenderLayer::scrollToOffset(int, int, WebCore::RenderLayer::ScrollOffsetClamping)
 420.25 KB       1.0%	1681	 	      WebCore::RenderLayer::updateScrollInfoAfterLayout()
 420.25 KB       1.0%	1681	 	       WebCore::RenderBlock::updateScrollInfoAfterLayout()
 420.25 KB       1.0%	1681	 	        WebCore::RenderBlock::layoutBlock(bool, int, WebCore::RenderBlock::BlockLayoutPass)
 420.25 KB       1.0%	1681	 	         WebCore::RenderBlock::layout()
    256 Bytes    0.0%	1	 	    WebCore::ScrollableArea::didAddVerticalScrollbar(WebCore::Scrollbar*)
    256 Bytes    0.0%	1	 	    WebCore::FrameView::contentsResized()

We should find a way to avoid creating the RenderLayer ones unless they're actually needed.
Comment 1 Andreas Kling 2011-12-18 18:25:59 PST
Created attachment 119794 [details]
Proposed patch
Comment 2 Darin Adler 2011-12-18 18:41:59 PST
Comment on attachment 119794 [details]
Proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=119794&action=review

> Source/WebCore/platform/ScrollableArea.cpp:133
> +    if (!m_scrollAnimator && !offset.x() && !offset.y())
> +        return;

This is a great idea. But I don’t think this it is technically correct; the offset might already be something other than 0,0 if it was already scrolled by a call to setScrollOffset rather than a call to scrollToOffsetWithoutAnimation. It would be great to have this check in ScrollableArea, but at the moment it seems impractical to do it correctly given what’s abstract in the class and what’s concrete.

Instead, I suggest putting a check into RenderLayer::scrollToOffset:

    IntPoint newScrollOffset(x, y);
    if (newScrollOffset != scrollOffset())

I also noticed two other things:

1) In RenderLayer there are two calls that use explicit ScrollableArea prefixes where they need not: This one and the call to ScrollableArea::setConstrainsScrollingToContentEdge.

2) There is a unpleasant mix of float, int, and LayoutUnit in RenderLayer and ScrollableArea. It’s bizarre that scrollToOffsetWithoutAnimation takes a FloatPoint, setScrollOffset takes an IntPoint, and scrollToOffset takes a LayoutUnit. There may be some reason why, but I am not clear what it is.
Comment 3 Andreas Kling 2011-12-19 09:38:31 PST
Created attachment 119872 [details]
Proposed patch v2
Comment 4 Beth Dakin 2011-12-19 09:44:50 PST
Comment on attachment 119872 [details]
Proposed patch v2

Looks good!
Comment 5 Andreas Kling 2011-12-19 10:11:32 PST
Committed r103245: <http://trac.webkit.org/changeset/103245>