Open Bug 1351231 Opened 5 years ago Updated 2 months ago

Implement PFetch protocol and backing FetchService to allow Workers to request fetches without involving the main thread of their process

Categories

(Core :: DOM: Networking, enhancement, P3)

enhancement

Tracking

()

ASSIGNED
Performance P2

People

(Reporter: bkelly, Assigned: edenchuang)

References

(Blocks 5 open bugs)

Details

(Keywords: perf:pageload, Whiteboard: [necko-triaged])

Attachments

(5 files, 1 obsolete file)

Currently fetch() using nsIChannel on the main thread in the current process.  This means that a worker thread (like service worker) can hit main thread jank when it tries to perform a network request.  This is particularly bad for service workers since delaying the fetch() may in turn delay the network result for the main page load.

The network team is working on making nsIChannel support PBackground so it can be used OMT.  That will probably take a long time to fully happen, however.

In addition, our service worker e10s refactor will move the service worker instances to a new process.  That will also take some time to happen.  Its also possible the memory overhead of this new process will be too large.

An alternative we could do in the short term would be to implement a separate PBackground actor just for fetch().  We already support serializing Request and Response objects across IPC in the Cache API.  In addition, Andrea recently landed parent-to-child AutoIPCStream support.  Between these it might be easy to use PBackground to go to parent, proxy to main thread there, and then create the nsIChannel.

If we did this, though, we would not be able to fully remove the current implementation.  A PBackground fetch() would bypass the child-side service worker intercept today.  We would only be able to use it in fetch() calls from within the service worker global itself.  Eventually we could remove the old fetch() implementation after SWM is moved to the parent.
Priority: -- → P3
We may want to do this even with the necko changes.  Right now I think they are only making OnDataAvailable() work OMT which means we still need to touch main thread for On(Start|Stop)Request().

Another factor to consider, though, is we would need to do something special for devtools.  It currently requires nsIChannel in order to show up in the network monitor.
Blocks: 1330826
Priority: P3 → P2
Whiteboard: [qf]
Blocks: 1522316
Whiteboard: [qf] → [qf:p1:pageload]

Note: From a conversation with Dragana on Feb 14, 2019, I understand the plan is to make AsyncOpen, OnStart, and OnStop work off the main thread, so this bug probably wants to be duped.

Component: DOM: Service Workers → DOM: Networking
Priority: P2 → --
Depends on: omt-asyncopen
Priority: -- → P2
Whiteboard: [qf:p1:pageload] → [qf:p1:pageload][necko-triaged]
Priority: P2 → P3
See Also: → 1567556
Blocks: 1613912
Blocks: 1567556
Assignee: nobody → bugmail
Status: NEW → ASSIGNED
Summary: Consider using separate PBackground actor for fetch() → Implement PFetch protocol and backing FetchService to allow Workers to request fetches without involving the main thread of their process
Assignee: bugmail → ytausky
Whiteboard: [qf:p1:pageload][necko-triaged] → [qf:p2:pageload][necko-triaged]

Does this block parsing worklets as module scripts, i.e., bug 1572644?

(In reply to Anne (:annevk) from comment #4)

Does this block parsing worklets as module scripts, i.e., bug 1572644?

No. One could implement bug 1311726 while still performing the current "let's do all the network stuff on the main thread" behavior. Noting that right now the worklet script loader just assumes the one single invocation of WorkletFetchHandler that feeds into the module compilation.

The network-on-the-main-thread uses could then subsequently be replaced with PFetch later on.

Blocks: 1290958
No longer depends on: omt-asyncopen
Assignee: ytausky → echuang
Depends on: 1725567
No longer blocks: 1290958
Performance: --- → P2
Keywords: perf:pageload
Whiteboard: [qf:p2:pageload][necko-triaged] → [necko-triaged]
Attachment #9270005 - Attachment is obsolete: true
Attachment #9270007 - Attachment description: WIP: Bug 1351231 - FetchService integration for PFetch. → Bug 1351231 - FetchService integration for PFetch.
Attachment #9270006 - Attachment description: WIP: Bug 1351231 - PFetch protocol declaration and implementation. → Bug 1351231 - PFetch protocol declaration and implementation.
Attachment #9270006 - Attachment description: Bug 1351231 - PFetch protocol declaration and implementation. → Bug 1351231 - PFetch protocol declaration and implementation. r=#dom-worker-reviewers
Attachment #9270007 - Attachment description: Bug 1351231 - FetchService integration for PFetch. → Bug 1351231 - FetchService integration for PFetch. r=#dom-worker-reviewers
You need to log in before you can comment on or make changes to this bug.