Bug 192620 - [DFG][FTL] Add NewSymbol
Summary: [DFG][FTL] Add NewSymbol
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-12-12 02:50 PST by Yusuke Suzuki
Modified: 2018-12-13 11:27 PST (History)
6 users (show)

See Also:


Attachments
WIP (18.25 KB, patch)
2018-12-12 02:58 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (21.32 KB, patch)
2018-12-12 07:01 PST, Yusuke Suzuki
saam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2018-12-12 02:50:37 PST
[DFG][FTL] Add NewSymbol
Comment 1 Yusuke Suzuki 2018-12-12 02:58:21 PST
Created attachment 357116 [details]
WIP
Comment 2 Yusuke Suzuki 2018-12-12 07:01:38 PST
Created attachment 357123 [details]
Patch
Comment 3 Saam Barati 2018-12-12 10:10:33 PST
Comment on attachment 357123 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:9
> +        NewSymbol code faster. Rather than that, this patch intends to offer SpecSymbol type information into DFG's

Do you think it could be worth inlining the allocation for this in another patch?

> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:9662
> +    // Known String.

You should assert instead of comment
Comment 4 Saam Barati 2018-12-12 10:12:01 PST
Comment on attachment 357123 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:14
> +        itself does not perform any type checks. Since `NewSymbol` will not exit except for OOM, we can just use ToString

It’s worth saying this is because ToString performs effects but NewSymbol doesn’t. Also, I don’t think we will ever OOM here, we will just crash
Comment 5 Yusuke Suzuki 2018-12-12 18:05:40 PST
Comment on attachment 357123 [details]
Patch

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

>> Source/JavaScriptCore/ChangeLog:9
>> +        NewSymbol code faster. Rather than that, this patch intends to offer SpecSymbol type information into DFG's
> 
> Do you think it could be worth inlining the allocation for this in another patch?

One problem is that every Symbol has an unique WTF::SymbolImpl, which is allocated from bmalloc heap.
While we can allocate Symbol JSCell in the inline code, we still need to call C runtime to allocate this SymbolImpl.
If it still offers a perf win, it would be worth doing since Symbol creation would be more frequent after class private fields come.

>> Source/JavaScriptCore/ChangeLog:14
>> +        itself does not perform any type checks. Since `NewSymbol` will not exit except for OOM, we can just use ToString
> 
> It’s worth saying this is because ToString performs effects but NewSymbol doesn’t. Also, I don’t think we will ever OOM here, we will just crash

Sounds nice. Fixed.

>> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:9662
>> +    // Known String.
> 
> You should assert instead of comment

Nice, fixed.
Comment 6 Yusuke Suzuki 2018-12-12 18:09:33 PST
Committed r239142: <https://trac.webkit.org/changeset/239142>
Comment 7 Radar WebKit Bug Importer 2018-12-12 18:10:27 PST
<rdar://problem/46683296>
Comment 8 Yusuke Suzuki 2018-12-13 00:17:47 PST
(In reply to Saam Barati from comment #3)
> Comment on attachment 357123 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=357123&action=review
> 
> > Source/JavaScriptCore/ChangeLog:9
> > +        NewSymbol code faster. Rather than that, this patch intends to offer SpecSymbol type information into DFG's
> 
> Do you think it could be worth inlining the allocation for this in another
> patch?

After investigating, inlining allocation does not improve Symbol constructor calls much. Actually, the large part of the time is consumed by HashTable, which is used to ensure one-on-one correspondence betweeen Symbol* and WTF::SymbolImpl.
Comment 9 Saam Barati 2018-12-13 08:22:05 PST
(In reply to Yusuke Suzuki from comment #8)
> (In reply to Saam Barati from comment #3)
> > Comment on attachment 357123 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=357123&action=review
> > 
> > > Source/JavaScriptCore/ChangeLog:9
> > > +        NewSymbol code faster. Rather than that, this patch intends to offer SpecSymbol type information into DFG's
> > 
> > Do you think it could be worth inlining the allocation for this in another
> > patch?
> 
> After investigating, inlining allocation does not improve Symbol constructor
> calls much. Actually, the large part of the time is consumed by HashTable,
> which is used to ensure one-on-one correspondence betweeen Symbol* and
> WTF::SymbolImpl.

Makes sense. Thanks for investigating.

If we ever found a use case where this is super hot, we could inline cache Symbol(), e.g, a program like this:
function foo() { return Symbol(“const string”) }
Where foo is frequently called. We could cache the underlying SymbolImpl
Comment 10 Yusuke Suzuki 2018-12-13 08:33:11 PST
(In reply to Saam Barati from comment #9)
> 
> Makes sense. Thanks for investigating.
> 
> If we ever found a use case where this is super hot, we could inline cache
> Symbol(), e.g, a program like this:
> function foo() { return Symbol(“const string”) }
> Where foo is frequently called. We could cache the underlying SymbolImpl

The issue is that, everytime foo is called, it generates a new unique Symbol with unique SymbolImpl. So we cannot perform IC here.
One fancy plan is that, embedding SymbolImpl into Symbol*. And Symbol* won't be collected while SymbolImpl's ref count is larger than one (this could be implemented by marking constraints).
But the problem is, one SymbolImpl generated by VM cannot be used by the other VM.
So, if we would like to do this optimization, I think we need per-process VM heap.
Comment 11 Saam Barati 2018-12-13 11:27:35 PST
Makes sense. I clearly forgot that we have the 1:1 mapping of SymbolImpl to Symbol*