Bug 216199 - Remove storage WorkQueue in NetworkProcess
Summary: Remove storage WorkQueue in NetworkProcess
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: Sihui Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-09-04 16:39 PDT by Sihui Liu
Modified: 2020-09-08 14:53 PDT (History)
8 users (show)

See Also:


Attachments
Patch (18.39 KB, patch)
2020-09-04 16:51 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch for landing (17.99 KB, patch)
2020-09-08 12:14 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sihui Liu 2020-09-04 16:39:11 PDT
...
Comment 1 Sihui Liu 2020-09-04 16:51:29 PDT
Created attachment 408045 [details]
Patch
Comment 2 youenn fablet 2020-09-08 10:12:52 PDT
Comment on attachment 408045 [details]
Patch

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

> Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:544
> +void IDBServer::collectOriginsForVersion(const String& versionPath, HashSet<WebCore::SecurityOriginData>& securityOrigins) const

Can we make it a static function instead of a method?

> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:69
> +        LockHolder locker(m_server->lock());

Shouldn't we lock in getOrigins instead?

> Source/WebKit/NetworkProcess/NetworkProcess.cpp:1560
> +                callbackAggregator->m_websiteData.entries.append({ origins.takeAny(), WebsiteDataType::IndexedDBDatabases, 0 });

It seems we could return a Vector.
We added an optimisation for Vector::isolatedCopy() const && which would be nice as well to use.
Comment 3 Sihui Liu 2020-09-08 10:35:37 PDT
(In reply to youenn fablet from comment #2)
> Comment on attachment 408045 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=408045&action=review
> 
> > Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:544
> > +void IDBServer::collectOriginsForVersion(const String& versionPath, HashSet<WebCore::SecurityOriginData>& securityOrigins) const
> 
> Can we make it a static function instead of a method?
> 
Sure.

> > Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:69
> > +        LockHolder locker(m_server->lock());
> 
> Shouldn't we lock in getOrigins instead?
> 
No, we hold this lock when performing task on IDB thread; so if we acquire this lock on the main thread, background thread will be stopped.

> > Source/WebKit/NetworkProcess/NetworkProcess.cpp:1560
> > +                callbackAggregator->m_websiteData.entries.append({ origins.takeAny(), WebsiteDataType::IndexedDBDatabases, 0 });
> 
> It seems we could return a Vector.
> We added an optimisation for Vector::isolatedCopy() const && which would be
> nice as well to use.

Where do you suggest using Vector? You mean appendVector() here?
Comment 4 youenn fablet 2020-09-08 10:42:40 PDT
Comment on attachment 408045 [details]
Patch

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

>>> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:69
>>> +        LockHolder locker(m_server->lock());
>> 
>> Shouldn't we lock in getOrigins instead?
> 
> No, we hold this lock when performing task on IDB thread; so if we acquire this lock on the main thread, background thread will be stopped.

I meant in IDBServer::getOrigins, not WebIDBServer::getOrigins.
You are calling m_server->lock() and then m_server->getOrigins(), it seems it could be optimised

>>> Source/WebKit/NetworkProcess/NetworkProcess.cpp:1560
>>> +                callbackAggregator->m_websiteData.entries.append({ origins.takeAny(), WebsiteDataType::IndexedDBDatabases, 0 });
>> 
>> It seems we could return a Vector.
>> We added an optimisation for Vector::isolatedCopy() const && which would be nice as well to use.
> 
> Where do you suggest using Vector? You mean appendVector() here?

If getOrigins returns a Vector, we could use the Vector optimised of crossThreadCopy() and potentially use map here.
We might still need a HashSet to remove duplicates.
Recreating a HashSet through crossThreadCopy() is probably less efficient than a Vector created from a HashSet.
Or maybe we could try to optimise HashSet isolatedCopy in cases where all entries are already isolated.
Comment 5 Sihui Liu 2020-09-08 12:11:05 PDT
Comment on attachment 408045 [details]
Patch

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

>>>> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:69
>>>> +        LockHolder locker(m_server->lock());
>>> 
>>> Shouldn't we lock in getOrigins instead?
>> 
>> No, we hold this lock when performing task on IDB thread; so if we acquire this lock on the main thread, background thread will be stopped.
> 
> I meant in IDBServer::getOrigins, not WebIDBServer::getOrigins.
> You are calling m_server->lock() and then m_server->getOrigins(), it seems it could be optimised

I see, yeah, that makes sense, but this is how we do all the tasks right now: holding lock in WebIDBServer and verify lock is held in IDBServer, so I will keep it this way for now.

>>>> Source/WebKit/NetworkProcess/NetworkProcess.cpp:1560
>>>> +                callbackAggregator->m_websiteData.entries.append({ origins.takeAny(), WebsiteDataType::IndexedDBDatabases, 0 });
>>> 
>>> It seems we could return a Vector.
>>> We added an optimisation for Vector::isolatedCopy() const && which would be nice as well to use.
>> 
>> Where do you suggest using Vector? You mean appendVector() here?
> 
> If getOrigins returns a Vector, we could use the Vector optimised of crossThreadCopy() and potentially use map here.
> We might still need a HashSet to remove duplicates.
> Recreating a HashSet through crossThreadCopy() is probably less efficient than a Vector created from a HashSet.
> Or maybe we could try to optimise HashSet isolatedCopy in cases where all entries are already isolated.

I see, so you suggest that IDBServer::getOrigins() returns Vector and WebIDBServer::getOrigins makes a crossThreadCopy of the Vector? 
In NetworkProcess, we have filterForRegistrableDomains that takes HashSet, so seems it's more convenient to use HashSet there and as you said, maybe optimize isolatedCopy of HashSet.
Comment 6 Sihui Liu 2020-09-08 12:14:48 PDT
Created attachment 408253 [details]
Patch for landing
Comment 7 EWS 2020-09-08 12:37:47 PDT
Committed r266742: <https://trac.webkit.org/changeset/266742>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408253 [details].
Comment 8 Radar WebKit Bug Importer 2020-09-08 12:38:19 PDT
<rdar://problem/68524066>