RESOLVED FIXED 136584
Laying out a TextRun using an SVG font is O(n^2)
https://bugs.webkit.org/show_bug.cgi?id=136584
Summary Laying out a TextRun using an SVG font is O(n^2)
Myles C. Maxfield
Reported 2014-09-05 13:15:20 PDT
SVGTextRunRenderingContext::glyphDataForCharacter() (called for each character in a run) calls SVGFontData::applySVGGlyphSelection(), which calls Font::normalizeSpaces() on the entire rest of the run (which is O(n))
Attachments
Patch (145.24 KB, patch)
2014-09-05 19:23 PDT, Myles C. Maxfield
kling: review+
Myles C. Maxfield
Comment 1 2014-09-05 19:23:27 PDT
Myles C. Maxfield
Comment 2 2014-09-05 19:24:53 PDT
Comment on attachment 237728 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=237728&action=review > Source/WebCore/platform/graphics/TextRun.h:239 > + mutable String m_normalizedSpaces; We may want this cached value to live in WidthIterator::advanceInternal() instead of in TextRun.
Andreas Kling
Comment 3 2014-09-05 19:43:06 PDT
Comment on attachment 237728 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=237728&action=review r=me > Source/WebCore/platform/graphics/TextRun.cpp:61 > + if (m_normalizedSpaces.length() != static_cast<unsigned>(charactersLength())) { Could do early return here. >> Source/WebCore/platform/graphics/TextRun.h:239 >> + mutable String m_normalizedSpaces; > > We may want this cached value to live in WidthIterator::advanceInternal() instead of in TextRun. I agree.
Myles C. Maxfield
Comment 4 2014-09-05 21:58:48 PDT
Carlos Alberto Lopez Perez
Comment 5 2014-09-06 07:50:39 PDT
Darin Adler
Comment 6 2014-09-06 17:45:54 PDT
Comment on attachment 237728 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=237728&action=review > Source/WebCore/platform/graphics/Font.h:273 > + static inline bool treatAsSpace(UChar c) { return c == ' ' || c == '\t' || c == '\n' || c == noBreakSpace; } > + static inline bool treatAsZeroWidthSpace(UChar c) { return treatAsZeroWidthSpaceInComplexScript(c) || c == 0x200c || c == 0x200d; } > + static inline bool treatAsZeroWidthSpaceInComplexScript(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == softHyphen || c == zeroWidthSpace || (c >= 0x200e && c <= 0x200f) || (c >= 0x202a && c <= 0x202e) || c == zeroWidthNoBreakSpace || c == objectReplacementCharacter; } These changes are unnecessary and unhelpful. They should have no effect on whether the functions get inlined. > Source/WebCore/platform/graphics/TextRun.cpp:63 > + m_normalizedSpaces = String(data8(0), charactersLength()); characters8() rather than data8(0) But why copy these characters into a String? Why not just pass this pointer and length to Font::normalizeSpaces? > Source/WebCore/platform/graphics/TextRun.cpp:66 > + m_normalizedSpaces = String(data16(0), charactersLength()); characters16() rather than data16(0) But why copy these characters into a String? Why not just pass this pointer and length to Font::normalizeSpaces?
Csaba Osztrogonác
Comment 7 2014-09-08 09:15:25 PDT
Are you planning to fix or skip this new but failing performance test?
Csaba Osztrogonác
Comment 8 2014-09-09 05:33:03 PDT
Myles C. Maxfield
Comment 9 2014-09-10 11:57:27 PDT
Comment on attachment 237728 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=237728&action=review >> Source/WebCore/platform/graphics/Font.h:273 >> + static inline bool treatAsZeroWidthSpaceInComplexScript(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == softHyphen || c == zeroWidthSpace || (c >= 0x200e && c <= 0x200f) || (c >= 0x202a && c <= 0x202e) || c == zeroWidthNoBreakSpace || c == objectReplacementCharacter; } > > These changes are unnecessary and unhelpful. They should have no effect on whether the functions get inlined. I believe I have created a patch a few months ago where I created a tiny static function and you instructed me to make it inline. What is the best practice for this? Undone. >> Source/WebCore/platform/graphics/TextRun.cpp:63 >> + m_normalizedSpaces = String(data8(0), charactersLength()); > > characters8() rather than data8(0) > > But why copy these characters into a String? Why not just pass this pointer and length to Font::normalizeSpaces? Done. Whoops. This was a case of not seeing the forest for the trees. Done. >> Source/WebCore/platform/graphics/TextRun.cpp:66 >> + m_normalizedSpaces = String(data16(0), charactersLength()); > > characters16() rather than data16(0) > > But why copy these characters into a String? Why not just pass this pointer and length to Font::normalizeSpaces? Done. Done.
Myles C. Maxfield
Comment 10 2014-09-10 11:59:24 PDT
Addressing Darin's comments in https://trac.webkit.org/r173476
Note You need to log in before you can comment on or make changes to this bug.