Laying out a TextRun using an SVG font is O(n^2)
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Sep 2014 04:14:15 +0000 (04:14 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Sep 2014 04:14:15 +0000 (04:14 +0000)
commitf40adb0b19f2fcf2ba018a4ea6243b4779e2bb86
tree62e1609ee2939d4e299d7e762d48fd9515c5152b
parent94018a0a4d484d7f73ff61297ec6df305db981c2
Laying out a TextRun using an SVG font is O(n^2)
https://bugs.webkit.org/show_bug.cgi?id=136584

Reviewed by Andreas Kling.

PerformanceTests:

Time how long it takes to lay out and render some text using an SVG font.

* SVG/SVG-Text.html: Added.
* SVG/resources/graffiti.svg: Added.

Source/WebCore:

Caching the version of the run with normalized spaces leads to a 5x speedup on the
performance test this patch adds.

Note that SVGFontData::applySVGGlyphSelection() is still unnecesarrily O(n), so more
work can be done here. In particular, the call to collectGlyphsForString() can likely
be sped up.

No new correctness tests because there is no behavior change.
Performance Test: SVG/SVG-Text.html

* platform/graphics/Font.h:
(WebCore::Font::treatAsSpace): Make inline.
(WebCore::Font::treatAsZeroWidthSpace): Ditto.
(WebCore::Font::treatAsZeroWidthSpaceInComplexScript): Ditto.
* platform/graphics/SimpleFontData.h: Add String cache argument.
* platform/graphics/TextRun.h: Move member variables around for better packing.
(WebCore::TextRun::TextRun): Ditto.
* platform/graphics/WidthIterator.cpp: Add String cache argument.
(WebCore::WidthIterator::glyphDataForCharacter): Ditto.
(WebCore::WidthIterator::advanceInternal): Create String cache and pass it to
glyphDataForCharacter.
* platform/graphics/WidthIterator.h: Add String cache argument.
* rendering/svg/SVGTextRunRenderingContext.cpp: Ditto.
(WebCore::SVGTextRunRenderingContext::glyphDataForCharacter): Ditto.
* rendering/svg/SVGTextRunRenderingContext.h: Ditto.
* svg/SVGFontData.cpp:
(WebCore::SVGFontData::applySVGGlyphSelection): Call computeNormalizedSpaces
to consult with the cache.
(WebCore::computeNormalizedSpaces): Compute cached String value.
* svg/SVGFontData.h: Add String cache argument.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173349 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
PerformanceTests/ChangeLog
PerformanceTests/SVG/SVG-Text.html [new file with mode: 0644]
PerformanceTests/SVG/resources/graffiti.svg [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/graphics/SimpleFontData.h
Source/WebCore/platform/graphics/TextRun.h
Source/WebCore/platform/graphics/WidthIterator.cpp
Source/WebCore/platform/graphics/WidthIterator.h
Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp
Source/WebCore/rendering/svg/SVGTextRunRenderingContext.h
Source/WebCore/svg/SVGFontData.cpp
Source/WebCore/svg/SVGFontData.h