Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
Example URL:
Steps to reproduce the problem:
1. Initialize a web worker which periodically makes network requests (I've tested with XMLHttpRequests and WebSockets).
2. Block the main thread (eg with an infinite while loop, or a blocking dialog).
What is the expected behavior?
The background thread issues the XMLHttpRequests, even whilst the main thread is blocked.
What went wrong?
Although the background thread continues to make progress whilst the main thread is blocked, the network requests aren't issued. Concretely, the XMLHttpRequest objects are created, and code following their creation is executed, but the requests are not issued until the main thread is unblocked (I've confirmed this by looking at the logs in my test server).
I've attached sample files for the main thread and worker thread that illustrate the problem. These are contrived examples, but they illustrate the problem quite well. The blocking while loop could easily be replaced by other blocking code (eg a call to window.alert). I've also attached a summary of the relevant log messages.
A separate issue here is that printing log messages from the background appears to also be blocked by the main thread. That seems reasonable though, and it's still clear from the logs that execution is not generally blocked in the background thread: it's just blocked for the XHRs.
Did this work before? N/A
Chrome version: 38.0.2125.111 Channel: stable
OS Version: OS X 10.10.0
Flash Version: Shockwave Flash 15.0 r0

MessageChannel communication between workers is also blocked when the UI thread is blocked. Details here: http://forums.infamous.io/t/web-worker-performance-tests/21/16?u=joe
Communication between workers works fine in Firefox and IE, and is very very important for designing performant applications.
Please fix this as soon as possible. Thanks!

This issue has been available for more than 365 days, and should be re-evaluated. Please re-triage this issue.
The Hotlist-Recharge-Cold label is applied for tracking purposes, and should not be removed after re-triaging the issue.
For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Here are the tentative key results for Q1:
1. Estimate performance gain.
2. Have some doc/plan about how to implement.
3. Start committing code.
It's hard for us to gauge the priority of this performance issue vs. the remaining opportunity for SW startup latencies. Please consider sharing any data about impact.

I created a test page (https://goo.gl/GxUykR) using Google Map API JavaScript
file. This page shows a map with a marker. The ServiceWorker calls
"respondWith(fetch())" to passes the requests from the page through fetch API.
I measured the time between the navigation start and onLoad event with Nexus 4.
The average of 10 times results are:
- No ServiceWorker : 2.89 sec
- With ServiceWorker : 3.87 sec
- With ServiceWorker in different process : 3.11 sec
- With ServiceWorker with a priority hack (*1) : 3.73 sec
*1: This patch sets ServiceWorker initiated tasks highest priority.
https://codereview.chromium.org/2649063002/
I created a patch (*2) to record detailed time breakdown of requests.
*2: https://codereview.chromium.org/2654663004/
This is the result and the trace log:
Result: https://goo.gl/qGDTuN Trace: https://goo.gl/rYQ3UN
According to the result and the trace log:
- The page load is actually delayed by the intensive main thread.
- When the ServiceWorker is in a different process from the page's renderer
process, the page load is not largely delayed.
- We can see a slight improvement of the hack (*1). But it is not so big.
- The FetchEvent is throttled in the browser process after receiving the
request from the page before creating the ServiceWorkerURLRequestJob.
I will write some doc/plan about how to implement.

There is another issue in FetchEvent.respondWith() that the data flow from the SW thread to the browser process is using BlobRegistry Stream which sends the IPC from the main thread.
I created another issue. ( crbug.com/690795 )
And I'm still investigating how to make it possible to call fetch() without going to the main thread.

I created a demo patch of "Mojo pipe respondWith" and "Off main thread fetch" (bypassing security checks), and measured the impact for time to onload event.
https://goo.gl/hrh3st
According to the result histogram, this can make the same-process SW as fast as the different-process SW.
I'm still investigating the design.

The CLs above have introduced flakes on Win7 (dbg) in these tests
SSLUIWorkerFetchTest.MixedContentSubFrame
SSLUIWorkerFetchTest.MixedContentSettings
SSLUIWorkerFetchTest.MixedContentSettingsWithBlockingCSP
See https://uberchromegw.corp.google.com/i/chromium.win/builders/Win7%20Tests%20%28dbg%29%281%29?numbuilds=25.
I disable these tests on Windows dbg.
Example error message:
[ RUN ] SSLUIWorkerFetchTest.MixedContentSubFrame/2
[5444:3880:0801/034139.276:WARNING:chrome_browser_main_win.cc(483)] Command line too long for RegisterApplicationRestart: --brave-new-test-launcher --cfi-diag=0 --gtest_also_run_disabled_tests --gtest_filter=SSLUIWorkerFetchTest.MixedContentSubFrame/2 --single_process --test-launcher-bot-mode --test-launcher-summary-output="e:\b\swarm_slave\w\ion0e1id\output.json" --user-data-dir="C:\Users\CHROME~2\AppData\Local\Temp\scoped_dir5940_30951\d5940_31634" --disable-offline-auto-reload --enable-features=OffMainThreadFetch --no-first-run --no-default-browser-check --enable-logging=stderr --safebrowsing-disable-auto-update --disable-default-apps --wm-window-animations-disabled --disable-component-update --test-type=browser --force-color-profile=srgb --disable-zero-browsers-open-for-tests --ipc-connection-timeout=45 --allow-file-access-from-files --dom-automation --log-gpu-control-list-decisions --disable-backgrounding-occluded-windows --disable-gl-drawing-for-tests --override-use-software-gl-for-tests --force-color-profile=srgb --disable-features=NetworkPrediction --flag-switches-begin --flag-switches-end --restore-last-session about:blank
[4780:5316:0801/034139.966:ERROR:direct_composition_surface_win.cc(1073)] Failing to detect HDR, couldn't retrieve D3D11 device from ANGLE.
[4780:5316:0801/034140.027:INFO:media_foundation_video_encode_accelerator_win.cc(335)] Windows versions earlier than 8 are not supported.
[5064:2720:0801/034144.992:ERROR:render_process_impl.cc(176)] WebFrame LEAKED 1 TIMES
[5444:3004:0801/034145.107:ERROR:process_win.cc(139)] Unable to terminate process: Access is denied. (0x5)
[5444:3880:0801/034145.563:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This request has been blocked; the content must be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[5444:3880:0801/034147.100:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This request has been blocked; the content must be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[5444:4312:0801/034150.076:WARNING:embedded_test_server.cc(219)] Request not handled. Returning 404: /favicon.ico
[4504:5140:0801/034150.133:ERROR:render_process_impl.cc(176)] WebFrame LEAKED 3 TIMES
[5444:3004:0801/034150.445:ERROR:process_win.cc(139)] Unable to terminate process: Access is denied. (0x5)
[3228:3936:0801/034151.915:ERROR:render_process_impl.cc(176)] WebFrame LEAKED 1 TIMES
[5444:3004:0801/034152.002:ERROR:process_win.cc(139)] Unable to terminate process: Access is denied. (0x5)
[5444:3880:0801/034152.278:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This request has been blocked; the content must be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[5444:3880:0801/034152.844:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This request has been blocked; the content must be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[5284:3796:0801/034201.037:ERROR:render_process_impl.cc(176)] WebFrame LEAKED 1 TIMES
[5444:3004:0801/034201.135:ERROR:process_win.cc(139)] Unable to terminate process: Access is denied. (0x5)
[5444:3880:0801/034201.888:WARNING:web_contents_impl.cc(3862)] https://127.0.0.1:53712/ ran insecure content from http://example.com:53713/worker_test_data.txt
[5444:3880:0801/034201.918:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This content should also be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[5444:3880:0801/034203.543:WARNING:web_contents_impl.cc(3862)] https://127.0.0.1:53712/ ran insecure content from http://example.com:53713/worker_test_data.txt
[5444:3880:0801/034203.552:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This content should also be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[6044:4136:0801/034212.290:ERROR:render_process_impl.cc(176)] WebFrame LEAKED 1 TIMES
[5444:3004:0801/034212.613:ERROR:process_win.cc(139)] Unable to terminate process: Access is denied. (0x5)
[5444:3880:0801/034213.115:WARNING:web_contents_impl.cc(3862)] https://127.0.0.1:53712/ ran insecure content from http://example.com:53713/worker_test_data.txt
[5444:3880:0801/034213.142:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This content should also be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[5444:3880:0801/034214.560:WARNING:web_contents_impl.cc(3862)] https://127.0.0.1:53712/ ran insecure content from http://example.com:53713/worker_test_data.txt
[5444:3880:0801/034214.573:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This content should also be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)
[5708:2328:0801/034217.365:ERROR:render_process_impl.cc(176)] WebFrame LEAKED 3 TIMES
[5444:3004:0801/034217.460:ERROR:process_win.cc(139)] Unable to terminate process: Access is denied. (0x5)
[5444:3880:0801/034221.977:INFO:CONSOLE(1)] "Mixed Content: The page at 'https://127.0.0.1:53712/worker.js' was loaded over HTTPS, but requested an insecure resource 'http://example.com:53713/worker_test_data.txt'. This request has been blocked; the content must be served over HTTPS.", source: https://127.0.0.1:53712/worker.js (1)