RESOLVED FIXED140873
Optimize matchesLangPseudoClass() of :lang()
https://bugs.webkit.org/show_bug.cgi?id=140873
Summary Optimize matchesLangPseudoClass() of :lang()
Dhi Aurrahman
Reported 2015-01-25 12:19:10 PST
Optimize matchesLangPseudoClass of :lang()
Attachments
Patch (6.27 KB, patch)
2015-01-25 12:26 PST, Dhi Aurrahman
no flags
Archive of layout-test-results from ews100 for mac-mavericks (681.60 KB, application/zip)
2015-01-25 13:11 PST, Build Bot
no flags
Archive of layout-test-results from ews104 for mac-mavericks-wk2 (813.48 KB, application/zip)
2015-01-25 13:20 PST, Build Bot
no flags
Patch (6.37 KB, patch)
2015-01-25 13:30 PST, Dhi Aurrahman
no flags
Patch (6.47 KB, patch)
2015-01-27 01:19 PST, Dhi Aurrahman
no flags
Patch (10.08 KB, patch)
2015-01-31 20:33 PST, Dhi Aurrahman
no flags
Patch (10.42 KB, patch)
2015-02-01 10:12 PST, Dhi Aurrahman
no flags
Patch (10.42 KB, patch)
2015-02-01 10:31 PST, Dhi Aurrahman
no flags
Patch (10.46 KB, patch)
2015-02-02 15:56 PST, Dhi Aurrahman
no flags
Dhi Aurrahman
Comment 1 2015-01-25 12:26:37 PST
Build Bot
Comment 2 2015-01-25 13:11:49 PST
Comment on attachment 245310 [details] Patch Attachment 245310 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/6575596767281152 New failing tests: fast/selectors/lang-valid-extended-filtering.html fast/selectors/lang-extended-filtering.html fast/selectors/lang-vs-xml-lang.html fast/selectors/lang-vs-xml-lang-xhtml.xhtml fast/selectors/lang-inheritance2.html fast/selectors/lang-inheritance.html
Build Bot
Comment 3 2015-01-25 13:11:52 PST
Created attachment 245311 [details] Archive of layout-test-results from ews100 for mac-mavericks The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews100 Port: mac-mavericks Platform: Mac OS X 10.9.5
Build Bot
Comment 4 2015-01-25 13:20:25 PST
Comment on attachment 245310 [details] Patch Attachment 245310 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/4613462432940032 New failing tests: fast/selectors/lang-valid-extended-filtering.html fast/selectors/lang-extended-filtering.html fast/selectors/lang-vs-xml-lang.html fast/selectors/lang-vs-xml-lang-xhtml.xhtml fast/selectors/lang-inheritance2.html fast/selectors/lang-inheritance.html
Build Bot
Comment 5 2015-01-25 13:20:27 PST
Created attachment 245312 [details] Archive of layout-test-results from ews104 for mac-mavericks-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews104 Port: mac-mavericks-wk2 Platform: Mac OS X 10.9.5
Dhi Aurrahman
Comment 6 2015-01-25 13:30:02 PST
Benjamin Poulain
Comment 7 2015-01-26 13:41:16 PST
Comment on attachment 245313 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=245313&action=review That looks like a good start. Something is fishy with the length handling though. Did you measure the before-after this patch on the microbenchmark? > Source/WebCore/css/SelectorCheckerTestFunctions.h:185 > + if (languageString[languageLength - 1] == '-') > + languageLength += 1; This looks very very fishy. A length for a buffer should never exceed the buffer size. > Source/WebCore/css/SelectorCheckerTestFunctions.h:206 > + if (rangeString[rangeLength - 1] == '-') > + rangeLength += 1; Very fishy again.
Dhi Aurrahman
Comment 8 2015-01-27 01:19:47 PST
Dhi Aurrahman
Comment 9 2015-01-27 01:24:09 PST
(In reply to comment #7) > Comment on attachment 245313 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=245313&action=review > > That looks like a good start. Something is fishy with the length handling > though. That was a cheap trick on handling '-' at the end of language or range. I have managed it to be removed in next patch. > > Did you measure the before-after this patch on the microbenchmark? Before: https://cloudup.com/ckxm_SuTIiO After: https://cloudup.com/ct6MMBNCSTv > > > Source/WebCore/css/SelectorCheckerTestFunctions.h:185 > > + if (languageString[languageLength - 1] == '-') > > + languageLength += 1; > > This looks very very fishy. > > A length for a buffer should never exceed the buffer size. > > > Source/WebCore/css/SelectorCheckerTestFunctions.h:206 > > + if (rangeString[rangeLength - 1] == '-') > > + rangeLength += 1; > > Very fishy again.
Darin Adler
Comment 10 2015-01-28 09:26:33 PST
Comment on attachment 245429 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=245429&action=review This is a fantastic project to do! I will say review+ but I would prefer that this use even more StringView and even less String, although that will require filling out more operations that we can do with StringView. > Source/WebCore/css/SelectorCheckerTestFunctions.h:135 > +ALWAYS_INLINE bool containslanguageSubtagMatchingRange(const StringView& language, const size_t& languageLength, const StringView& range, size_t& position) We should always use StringView, not const StringView&. > Source/WebCore/css/SelectorCheckerTestFunctions.h:139 > + const String& rangeString = range.toStringWithoutCopying(); We shouldn’t need to make a String here at all. If we define the right set of operations on StringView, then we can avoid the memory allocation entirely. And it helps us fill out the StringView class as needed for future use. > Source/WebCore/css/SelectorCheckerTestFunctions.h:180 > + const StringView& languageStringView = language.string(); Just StringView here, not const StringView&. > Source/WebCore/css/SelectorCheckerTestFunctions.h:181 > + const size_t& languageLength = languageStringView.length(); Just unsigned here, not const size_t&. > Source/WebCore/css/SelectorCheckerTestFunctions.h:190 > + const StringView& rangeStringView = range.string(); Just StringView, not const StringView&. > Source/WebCore/css/SelectorCheckerTestFunctions.h:194 > + size_t rangeSubtagsStartIndex = 0; > + size_t rangeSubtagsEndIndex = notFound; > + size_t lastMatchedLanguageSubtagIndex = 0; > + size_t rangeLength = rangeStringView.length(); These should all be unsigned, not size_t. > Source/WebCore/css/SelectorCheckerTestFunctions.h:204 > + const StringView& rangeSubtag = rangeStringView.substring(rangeSubtagsStartIndex, rangeSubtagsEndIndex - rangeSubtagsStartIndex); Just StringView, not const StringView&.
Benjamin Poulain
Comment 11 2015-01-28 15:23:40 PST
(In reply to comment #9) > > Did you measure the before-after this patch on the microbenchmark? > > Before: https://cloudup.com/ckxm_SuTIiO > After: https://cloudup.com/ct6MMBNCSTv Nice!
Dhi Aurrahman
Comment 12 2015-01-31 20:33:12 PST
Dhi Aurrahman
Comment 13 2015-02-01 10:12:09 PST
Dhi Aurrahman
Comment 14 2015-02-01 10:31:44 PST
Dhi Aurrahman
Comment 15 2015-02-01 12:17:09 PST
Comment on attachment 245834 [details] Patch I hope it will be fine to add some basic equality comparisons for StringVIew.
Darin Adler
Comment 16 2015-02-02 08:45:33 PST
Comment on attachment 245834 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=245834&action=review > Source/WTF/wtf/text/StringView.h:145 > +inline bool equal(StringView, StringView); > +inline bool equal(StringView, const LChar*); > +inline bool equal(StringView, const char*); > +inline bool equalIgnoringASCIICase(StringView, StringView); The inline keyword should be omitted here. It has no effect.
Dhi Aurrahman
Comment 17 2015-02-02 15:56:18 PST
WebKit Commit Bot
Comment 18 2015-02-02 18:22:02 PST
Comment on attachment 245910 [details] Patch Clearing flags on attachment: 245910 Committed r179532: <http://trac.webkit.org/changeset/179532>
WebKit Commit Bot
Comment 19 2015-02-02 18:22:07 PST
All reviewed patches have been landed. Closing bug.
Alexey Proskuryakov
Comment 20 2015-02-04 10:50:30 PST
ASan detected out of bounds access on multiple lang tests today, I suspect this change. fast/css-generated-content/quotes-lang.html fast/canvas/imagedata-contains-uint8clampedarray.html fast/selectors/lang-multiple.html fast/selectors/lang-inheritance2.html fast/selectors/lang-specificity-xml.xhtml fast/selectors/lang-extended-filtering.html fast/selectors/lang-valid-extended-filtering.html fast/selectors/lang-extended-filtering-with-string-arguments.html #1 0x10d798aa0 in unsigned int WTF::loadUnaligned<unsigned int>(char const*) #2 0x10d798981 in WTF::equal(WTF::StringView, unsigned char const*) #3 0x10d798861 in WTF::operator==(WTF::StringView, char const*) #4 0x10d795166 in WebCore::SelectorChecker::checkOne(WebCore::SelectorChecker::CheckingContextWithStatus const&, WebCore::PseudoIdSet&, WebCore::SelectorChecker::MatchType&, unsigned int&) const #5 0x10d791220 in WebCore::SelectorChecker::matchRecursively(WebCore::SelectorChecker::CheckingContextWithStatus const&, WebCore::PseudoIdSet&, unsigned int&) const
Alexey Proskuryakov
Comment 21 2015-02-04 13:01:43 PST
I don't think that this is an issue with the patch. Filed bug 141258 and bug 141259 for two aspects of the problem.
Note You need to log in before you can comment on or make changes to this bug.