Bug 130226 - [Mac] Avoid creating DOMCSSStyleDeclaration in WebHTMLConverter
Summary: [Mac] Avoid creating DOMCSSStyleDeclaration in WebHTMLConverter
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac (Intel) Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords:
Depends on:
Blocks: 130227
  Show dependency treegraph
 
Reported: 2014-03-13 23:33 PDT by Ryosuke Niwa
Modified: 2014-03-14 12:32 PDT (History)
6 users (show)

See Also:


Attachments
Extracted HTMLConverterCaches (26.20 KB, patch)
2014-03-13 23:37 PDT, Ryosuke Niwa
kling: review+
Details | Formatted Diff | Diff
A/B test result (22.59 KB, text/html)
2014-03-13 23:47 PDT, Ryosuke Niwa
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2014-03-13 23:33:42 PDT
Right now, we spend a significant amount of time creating Objective-C wrappers for CSSStyleDeclaration
and then looking up NSMutableDictionary.
Comment 1 Ryosuke Niwa 2014-03-13 23:37:32 PDT
Created attachment 226655 [details]
Extracted HTMLConverterCaches
Comment 2 Ryosuke Niwa 2014-03-13 23:47:38 PDT
Created attachment 226657 [details]
A/B test result

It's crazy.  This simple C++ rewrite is a 20% improvement.
Comment 3 Andreas Kling 2014-03-14 00:36:39 PDT
Comment on attachment 226655 [details]
Extracted HTMLConverterCaches

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

r=me

> Source/WebCore/platform/mac/HTMLConverter.mm:568
> +    auto result = m_computedStyles.add(element, nullptr);
> +    if (result.isNewEntry)
> +        result.iterator->value = CSSComputedStyleDeclaration::create(element, true);
> +    CSSStyleDeclaration* declaration = result.iterator->value.get();

This would be more efficient using ComputedStyleExtractor directly. Then we wouldn't have to build a CSSComputedStyleDeclaration object at all.

> Source/WebCore/platform/mac/HTMLConverter.mm:569
> +    return declaration ? declaration->getPropertyCSSValue(propertyName) : 0;

0 -> nullptr

> Source/WebCore/platform/mac/HTMLConverter.mm:577
> +    auto result = m_inlineStyles.add(element, nullptr);
> +    if (result.isNewEntry)
> +        result.iterator->value = element->style();
> +    CSSStyleDeclaration* declaration = result.iterator->value.get();

This code would be more efficient if it accessed the StyleProperties directly via Element::inlineStyle() instead of instantiating a CSSOM wrapper via style().

> Source/WebCore/platform/mac/HTMLConverter.mm:578
> +    return declaration ? declaration->getPropertyCSSValue(propertyName) : 0;

0 -> nullptr

> Source/WebCore/platform/mac/HTMLConverter.mm:785
> +        Element* element = toElement(coreNode);

I'd make this Element&.

> Source/WebCore/platform/mac/HTMLConverter.mm:1005
> +        Element* element = toElement(coreNode);

Same here.

> Source/WebCore/platform/mac/HTMLConverter.mm:2424
> +    _caches = nullptr;

Is this actually necessary?
Comment 4 Ryosuke Niwa 2014-03-14 01:04:24 PDT
(In reply to comment #3)
> (From update of attachment 226655 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=226655&action=review
>
> > Source/WebCore/platform/mac/HTMLConverter.mm:568
> > +    auto result = m_computedStyles.add(element, nullptr);
> > +    if (result.isNewEntry)
> > +        result.iterator->value = CSSComputedStyleDeclaration::create(element, true);
> > +    CSSStyleDeclaration* declaration = result.iterator->value.get();
> 
> This would be more efficient using ComputedStyleExtractor directly. Then we wouldn't have to build a CSSComputedStyleDeclaration object at all.

Can I store ComputedStyleExtractor in the hash map and use it later?
Comment 5 Andreas Kling 2014-03-14 10:17:52 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > (From update of attachment 226655 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=226655&action=review
> >
> > > Source/WebCore/platform/mac/HTMLConverter.mm:568
> > > +    auto result = m_computedStyles.add(element, nullptr);
> > > +    if (result.isNewEntry)
> > > +        result.iterator->value = CSSComputedStyleDeclaration::create(element, true);
> > > +    CSSStyleDeclaration* declaration = result.iterator->value.get();
> > 
> > This would be more efficient using ComputedStyleExtractor directly. Then we wouldn't have to build a CSSComputedStyleDeclaration object at all.
> 
> Can I store ComputedStyleExtractor in the hash map and use it later?

Totally.
Comment 6 Ryosuke Niwa 2014-03-14 12:32:46 PDT
Committed r165635: <http://trac.webkit.org/changeset/165635>