[webkit-changes] [WebKit/WebKit] 3abfea: Canvas::closePath should not iterate all segments ...

Yusuke Suzuki noreply at github.com
Fri Oct 27 14:16:49 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3abfea5879bc848536425a70f544846c5d281704
      https://github.com/WebKit/WebKit/commit/3abfea5879bc848536425a70f544846c5d281704
  Author: Yusuke Suzuki <ysuzuki at apple.com>
  Date:   2023-10-27 (Fri, 27 Oct 2023)

  Changed paths:
    M Source/WebCore/html/canvas/CanvasPath.cpp
    M Source/WebCore/platform/graphics/Path.cpp
    M Source/WebCore/platform/graphics/Path.h
    M Source/WebCore/platform/graphics/PathImpl.cpp
    M Source/WebCore/platform/graphics/PathImpl.h
    M Source/WebCore/platform/graphics/PathStream.cpp
    M Source/WebCore/platform/graphics/PathStream.h

  Log Message:
  -----------
  Canvas::closePath should not iterate all segments to compute subpath existence
https://bugs.webkit.org/show_bug.cgi?id=263753
rdar://117559394

Reviewed by Ryosuke Niwa.

Canvas#closePath is very hot in Speedometer3.0 and this is because it is calling fastBoundingRect
to compute bounding rect to see whether there is subpath. But we do not need to iterate all segments
since we can early return when the result gets the non-zero size, and quite likely, this gets non-zero
size just iterating one or two segments. Chart-chartjs is rendering charts via Canvas as a result its
path is very long. Iterating all segments every time we closePath is very costly.

This patch adds Path::hasSubpaths and PathImpl::hasSubpaths. PathImpl::hasSubpaths does the old generic
behavior, which takes fastBoundingRect and see whether its size is non-zero. But PathStream::hasSubpaths
has an optimization which stops iteration of segments when it starts seeing non-zero bounding rect.

* Source/WebCore/html/canvas/CanvasPath.cpp:
(WebCore::CanvasPath::closePath):
* Source/WebCore/platform/graphics/Path.cpp:
(WebCore::Path::hasSubpaths const):
* Source/WebCore/platform/graphics/Path.h:
* Source/WebCore/platform/graphics/PathImpl.cpp:
(WebCore::PathImpl::hasSubpaths const):
* Source/WebCore/platform/graphics/PathImpl.h:
* Source/WebCore/platform/graphics/PathStream.cpp:
(WebCore::PathStream::computeHasSubpaths):
(WebCore::PathStream::hasSubpaths const):
* Source/WebCore/platform/graphics/PathStream.h:

Canonical link: https://commits.webkit.org/269867@main




More information about the webkit-changes mailing list