Bug 103231 - Use AtomicString instead of AtomicStringImpl* in WebCore::RuleSet.
Summary: Use AtomicString instead of AtomicStringImpl* in WebCore::RuleSet.
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Hayato Ito
URL:
Keywords:
Depends on:
Blocks: 103394
  Show dependency treegraph
 
Reported: 2012-11-26 02:23 PST by Hayato Ito
Modified: 2012-11-28 01:19 PST (History)
9 users (show)

See Also:


Attachments
Use AtomicString (8.09 KB, patch)
2012-11-26 02:44 PST, Hayato Ito
no flags Details | Formatted Diff | Diff
Add isNull() check. (8.20 KB, patch)
2012-11-26 03:14 PST, Hayato Ito
koivisto: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hayato Ito 2012-11-26 02:23:41 PST
It seems we can use AtomicString instead of AtomicStringImpl* in WebCore::RuleSet without any performance regressions.
Comment 1 Hayato Ito 2012-11-26 02:44:53 PST
Created attachment 175948 [details]
Use AtomicString
Comment 2 Hayato Ito 2012-11-26 03:14:15 PST
Created attachment 175956 [details]
Add isNull() check.
Comment 3 Ojan Vafai 2012-11-26 09:20:02 PST
Comment on attachment 175956 [details]
Add isNull() check.

This seems reasonable to me. Do you know why AtomicStringImpl was used in the first place? What patch was this code added in?
Comment 4 Hayato Ito 2012-11-26 18:31:36 PST
(In reply to comment #3)
> (From update of attachment 175956 [details])
> This seems reasonable to me. Do you know why AtomicStringImpl was used in the first place? What patch was this code added in?

It's hard to find the first place. They were used at 94656 at least around CSS code base.
http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSStyleSelector.h?annotate=blame&rev=94656
Comment 5 Hayato Ito 2012-11-27 03:28:11 PST
It turned out that this replacement is not specific to WebCore::RuleSet. I think we can replace most of usage of AtomicStringImpl* with AtomicString in WebCore.

Let me use this patch as a pilot case. If things go well, I'll replace AtomicStringImpl* with AtomicString in other places in WebCore.

(In reply to comment #3)
> (From update of attachment 175956 [details])
> This seems reasonable to me. Do you know why AtomicStringImpl was used in the first place? What patch was this code added in?
Comment 6 Ojan Vafai 2012-11-27 08:43:55 PST
Now that I think about this more, the AtomicStringImpl* is the thing that's guaranteed to be unique for a given string, not the AtomicString*. So, if we're putting it in a map, we probably want to be putting in the impl, no?
Comment 7 Antti Koivisto 2012-11-27 08:52:00 PST
Comment on attachment 175956 [details]
Add isNull() check.

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

> Source/WebCore/ChangeLog:8
> +        Using AtomicString is preferred to using *AtomicStringImpl directly.  We

Rules like that exist to help people avoid mistakes with things they don't understand. This code is safe, the change just increases ref churn.
Comment 8 Ojan Vafai 2012-11-27 08:58:58 PST
(In reply to comment #7)
> (From update of attachment 175956 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=175956&action=review
> 
> > Source/WebCore/ChangeLog:8
> > +        Using AtomicString is preferred to using *AtomicStringImpl directly.  We
> 
> Rules like that exist to help people avoid mistakes with things they don't understand. This code is safe, the change just increases ref churn.

In fairness, code *should* generally use AtomicString. Anywhere we directly use AtomicStringImpl deserves a comment explaining why IMO.
Comment 9 Antti Koivisto 2012-11-27 09:06:17 PST
Fair enough. However should not run around the code base changing things that break some supposed rule unless they can show the change fixes a concrete bug. This has caused problems (and bugs!) in the past and has been extensively discussed on webkit-dev.
Comment 10 Hayato Ito 2012-11-27 22:18:47 PST
Okay. I'm okay to mark this WONTFIX.
It might not be worth doing this kind of refactoring.

(In reply to comment #9)
> Fair enough. However should not run around the code base changing things that break some supposed rule unless they can show the change fixes a concrete bug. This has caused problems (and bugs!) in the past and has been extensively discussed on webkit-dev.

Can I assume that we should use HashSet<AtomicString> instead of HashSet<AtomicStringImpl*> for *new* code? I could not find the discussion on webkit-dev.
Comment 11 Benjamin Poulain 2012-11-27 22:26:25 PST
(In reply to comment #10)
> Can I assume that we should use HashSet<AtomicString> instead of HashSet<AtomicStringImpl*> for *new* code?

No, not necessarily. HashSet<AtomicStringImpl*> is a better solution in some cases. It is not a case of an old code style, AtomicStringImpl* is a valid tool in our engineering toolbox.
Comment 12 Hayato Ito 2012-11-27 22:46:05 PST
Thank you.

I've just come up with the merit of using AtomicStringImpl* as a key in this case.
Since AtomicString defines implicit conversion constructors from String unfortunately, callers might pass String unintentionally without any warnings.
The pointer has a merit since String can not be a valid key if we use AtomicStringImpl* as a key.

(In reply to comment #11)
> (In reply to comment #10)
> > Can I assume that we should use HashSet<AtomicString> instead of HashSet<AtomicStringImpl*> for *new* code?
> 
> No, not necessarily. HashSet<AtomicStringImpl*> is a better solution in some cases. It is not a case of an old code style, AtomicStringImpl* is a valid tool in our engineering toolbox.
Comment 13 Hayato Ito 2012-11-27 23:33:37 PST
For the record, I've wrongly assumed that AtomicString has only a pointer to AtomicStringImpl as a member variable. So I thought there won't be any performance regression. That's wrong. AtomicString has a String as a member variable in fact.

(In reply to comment #12)
> Thank you.
> 
> I've just come up with the merit of using AtomicStringImpl* as a key in this case.
> Since AtomicString defines implicit conversion constructors from String unfortunately, callers might pass String unintentionally without any warnings.
> The pointer has a merit since String can not be a valid key if we use AtomicStringImpl* as a key.
> 
> (In reply to comment #11)
> > (In reply to comment #10)
> > > Can I assume that we should use HashSet<AtomicString> instead of HashSet<AtomicStringImpl*> for *new* code?
> > 
> > No, not necessarily. HashSet<AtomicStringImpl*> is a better solution in some cases. It is not a case of an old code style, AtomicStringImpl* is a valid tool in our engineering toolbox.
Comment 14 Hayato Ito 2012-11-28 01:19:30 PST
I recalled that my assumption came from the comment here:
http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSSelector.h#L198

        // AtomicString is really just an AtomicStringImpl* so the cast below is safe.
        // FIXME: Perhaps call sites could be changed to accept AtomicStringImpl?
        const AtomicString& value() const { return *reinterpret_cast<const AtomicString*>(m_hasRareData ? &m_data.m_rareData->m_value : &m_data.m_value); }


(In reply to comment #13)
> For the record, I've wrongly assumed that AtomicString has only a pointer to AtomicStringImpl as a member variable. So I thought there won't be any performance regression. That's wrong. AtomicString has a String as a member variable in fact.
> 
> (In reply to comment #12)
> > Thank you.
> > 
> > I've just come up with the merit of using AtomicStringImpl* as a key in this case.
> > Since AtomicString defines implicit conversion constructors from String unfortunately, callers might pass String unintentionally without any warnings.
> > The pointer has a merit since String can not be a valid key if we use AtomicStringImpl* as a key.
> > 
> > (In reply to comment #11)
> > > (In reply to comment #10)
> > > > Can I assume that we should use HashSet<AtomicString> instead of HashSet<AtomicStringImpl*> for *new* code?
> > > 
> > > No, not necessarily. HashSet<AtomicStringImpl*> is a better solution in some cases. It is not a case of an old code style, AtomicStringImpl* is a valid tool in our engineering toolbox.