Bug 200817 - Clarify StorageManagerSet / StorageManager threading model after r248734
Summary: Clarify StorageManagerSet / StorageManager threading model after r248734
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks: 200373
  Show dependency treegraph
 
Reported: 2019-08-16 09:34 PDT by Chris Dumez
Modified: 2019-08-16 15:06 PDT (History)
6 users (show)

See Also:


Attachments
Patch (15.01 KB, patch)
2019-08-16 09:38 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (15.21 KB, patch)
2019-08-16 09:45 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (15.60 KB, patch)
2019-08-16 10:13 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (17.25 KB, patch)
2019-08-16 10:49 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2019-08-16 09:34:18 PDT
Clarify StorageManagerSet / StorageManager threading model after r248734. StorageManager is now a background thread object but it still calls its completion handlers on the main thread, which is very error prone.
Comment 1 Chris Dumez 2019-08-16 09:38:32 PDT
Created attachment 376503 [details]
Patch
Comment 2 Chris Dumez 2019-08-16 09:45:00 PDT
Created attachment 376505 [details]
Patch
Comment 3 Sihui Liu 2019-08-16 10:05:01 PDT
Comment on attachment 376505 [details]
Patch

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

> Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp:188
>  void StorageManagerSet::getSessionStorageOrigins(PAL::SessionID sessionID, CompletionHandler<void(HashSet<WebCore::SecurityOriginData>&&)>&& completionHandler)

Probably not very related: CompletionHandler<void(HashSet<WebCore::SecurityOriginData>&&)>&& here can be changed to GetOriginsCallback&&.

> Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp:203
>  void StorageManagerSet::deleteSessionStorage(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)

CompletionHandler<void()>&& => DeleteCallback&&

> Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp:270
>  void StorageManagerSet::getLocalStorageOriginDetails(PAL::SessionID sessionID, CompletionHandler<void(Vector<LocalStorageDatabaseTracker::OriginDetails>&&)>&& completionHandler)

CompletionHandler<void(Vector<LocalStorageDatabaseTracker::OriginDetails>&&)>&& => GetOriginDetailsCallback&&
Comment 4 Chris Dumez 2019-08-16 10:13:17 PDT
Created attachment 376508 [details]
Patch
Comment 5 Geoffrey Garen 2019-08-16 10:35:28 PDT
Comment on attachment 376508 [details]
Patch

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

r=me

> Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp:279
> +        auto originDetails = storageManager->getLocalStorageOriginDetails();
> +        RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), originDetails = crossThreadCopy(originDetails)]() mutable {

Kind of unfortunate that this idiom creates a throw-away copy followed by a cross-thread copy.

Maybe we should consider renaming getLocalStorageOriginDetails() -> getLocalStorageOriginDetailsCrossThreadCopy(), and change the implementation to produce a crossThreadCopy.
Comment 6 Chris Dumez 2019-08-16 10:36:36 PDT
Comment on attachment 376508 [details]
Patch

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

>> Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp:279
>> +        RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), originDetails = crossThreadCopy(originDetails)]() mutable {
> 
> Kind of unfortunate that this idiom creates a throw-away copy followed by a cross-thread copy.
> 
> Maybe we should consider renaming getLocalStorageOriginDetails() -> getLocalStorageOriginDetailsCrossThreadCopy(), and change the implementation to produce a crossThreadCopy.

Ok, I can do that.
Comment 7 Chris Dumez 2019-08-16 10:40:36 PDT
(In reply to Chris Dumez from comment #6)
> Comment on attachment 376508 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=376508&action=review
> 
> >> Source/WebKit/NetworkProcess/WebStorage/StorageManagerSet.cpp:279
> >> +        RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), originDetails = crossThreadCopy(originDetails)]() mutable {
> > 
> > Kind of unfortunate that this idiom creates a throw-away copy followed by a cross-thread copy.
> > 
> > Maybe we should consider renaming getLocalStorageOriginDetails() -> getLocalStorageOriginDetailsCrossThreadCopy(), and change the implementation to produce a crossThreadCopy.
> 
> Ok, I can do that.

I would just like to point out that the previous code was already creating a throw-away copy since LocalStorageDatabaseTracker::originDetails() returns a new Vector. I merely moved the place where the Vector was crossThreadCopied.
Comment 8 Chris Dumez 2019-08-16 10:49:00 PDT
Created attachment 376510 [details]
Patch
Comment 9 Chris Dumez 2019-08-16 10:52:51 PDT
(In reply to Chris Dumez from comment #8)
> Created attachment 376510 [details]
> Patch

This latest iteration should have no perf impact as it always cross-thread-copies at the source.
Comment 10 Geoffrey Garen 2019-08-16 10:58:51 PDT
Comment on attachment 376510 [details]
Patch

r=me
Comment 11 Geoffrey Garen 2019-08-16 10:59:32 PDT
> I would just like to point out that the previous code was already creating a
> throw-away copy since LocalStorageDatabaseTracker::originDetails() returns a
> new Vector. I merely moved the place where the Vector was crossThreadCopied.

True! :P

I guess I only noticed this because the new code is clearer.
Comment 12 Chris Dumez 2019-08-16 11:01:26 PDT
(In reply to Geoffrey Garen from comment #11)
> > I would just like to point out that the previous code was already creating a
> > throw-away copy since LocalStorageDatabaseTracker::originDetails() returns a
> > new Vector. I merely moved the place where the Vector was crossThreadCopied.
> 
> True! :P
> 
> I guess I only noticed this because the new code is clearer.

Your point still stands for the other 2 calls sites. You just happened to comment on the only one when there is no perf-hit :P
Comment 13 WebKit Commit Bot 2019-08-16 11:15:28 PDT
Comment on attachment 376510 [details]
Patch

Clearing flags on attachment: 376510

Committed r248779: <https://trac.webkit.org/changeset/248779>
Comment 14 WebKit Commit Bot 2019-08-16 11:15:29 PDT
All reviewed patches have been landed.  Closing bug.
Comment 15 Radar WebKit Bug Importer 2019-08-16 15:06:22 PDT
<rdar://problem/54409115>