Bug 138376

Summary: Use lambda functions in DocumentOrderedMap
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: DOMAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, esprehn+autocc, kangil.han, kling, koivisto, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2
none
Patch none

Description Chris Dumez 2014-11-04 14:34:29 PST
Use lambda functions in DocumentOrderedMap instead of templates and separate named functions.
Comment 1 Chris Dumez 2014-11-04 15:15:27 PST
Created attachment 240958 [details]
Patch
Comment 2 WebKit Commit Bot 2014-11-04 15:18:25 PST
Attachment 240958 [details] did not pass style-queue:


ERROR: Source/WebCore/dom/DocumentOrderedMap.h:71:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 1 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Darin Adler 2014-11-04 15:21:34 PST
Comment on attachment 240958 [details]
Patch

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

> Source/WebCore/dom/DocumentOrderedMap.cpp:88
> +inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope, KeyMatchingFunction keyMatches) const

Seems like this might not get inlined as much as it did before. Are you sure there is no performance problem introduced here?
Comment 4 Chris Dumez 2014-11-04 15:24:28 PST
Comment on attachment 240958 [details]
Patch

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

>> Source/WebCore/dom/DocumentOrderedMap.cpp:88
>> +inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope, KeyMatchingFunction keyMatches) const
> 
> Seems like this might not get inlined as much as it did before. Are you sure there is no performance problem introduced here?

Hmm, this may be an issue indeed. I will verify.
Comment 5 Ryosuke Niwa 2014-11-04 16:06:18 PST
Did you run perf tests for this?
Comment 6 Chris Dumez 2014-11-04 16:21:23 PST
(In reply to comment #5)
> Did you run perf tests for this?

I will, as pointed out by Darin, it is likely I'll need to keep the function templated. However, we can still use lambdas.
Comment 7 Build Bot 2014-11-04 17:12:34 PST
Created attachment 240985 [details]
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-09  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 8 Chris Dumez 2014-11-04 17:17:56 PST
Comment on attachment 240958 [details]
Patch

I confirmed this regresses performance (~8% on getElementById). I'll re-upload a version keeping the function templated.
Comment 9 Chris Dumez 2014-11-04 17:28:37 PST
Created attachment 240990 [details]
Patch
Comment 10 Chris Dumez 2014-11-04 17:32:06 PST
I have confirmed that this new version does not regress performance. getElementById() actually seems to be ~2% faster now although I am not sure why.
Comment 11 Chris Dumez 2014-11-05 09:34:50 PST
I set the review flag again as the changes to the patch after the review were non-trivial.
Comment 12 Darin Adler 2014-11-06 07:22:08 PST
Comment on attachment 240990 [details]
Patch

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

> Source/WebCore/dom/DocumentOrderedMap.h:72
> +    template <typename KeyMatchingFunction>
> +    Element* get(const AtomicStringImpl&, const TreeScope&, const KeyMatchingFunction&) const;

I know we often format function template declarations like this on two lines, but I find it hard to see the structure here, with both lines flush left, but the second actually a continuation of the first. That’s why I prefer putting these into a single line, even if it makes the line long.
Comment 13 WebKit Commit Bot 2014-11-06 08:00:23 PST
Comment on attachment 240990 [details]
Patch

Clearing flags on attachment: 240990

Committed r175697: <http://trac.webkit.org/changeset/175697>
Comment 14 WebKit Commit Bot 2014-11-06 08:00:28 PST
All reviewed patches have been landed.  Closing bug.