#9889 closed enhancement (wontfix)
Use Web Workers for AJAX requests
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | ajax | Version: | 1.6.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Would it be possible to use HTML5 Web Workers to improve the performance of AJAX requests in jQuery?
It seems that Web Workers have access to the XMLHttpRequest object. Running AJAX requests, waiting for a response, and parsing the resulting JSON, in a separate thread will surely improve performance.
It would be nice if jQuery offered Web Worker-enabled AJAX requests as a feature included in jQuery by default.
Change History (5)
comment:1 Changed 12 years ago by
Component: | unfiled → ajax |
---|---|
Milestone: | None → 1.next |
Priority: | undecided → low |
Status: | new → open |
Version: | git → 1.6.2 |
comment:2 Changed 12 years ago by
Resolution: | → wontfix |
---|---|
Status: | open → closed |
I've spent a lot of time researching and experimenting with WebWorkers and I can definitively say that this is not a viable or realistic addition to jQuery core.
comment:4 Changed 12 years ago by
This is copied/pasted from -dev channel discussion:
- spin up cost of workers is gross
- it would be slower for single ajax requests
ie. GlobalScope [ postMessage() ] -> WorkerGlobalScope [ onmessage or addEventListener( message ...) ] -> XHR (request) (response) -> postMessage() -> GlobalScope [ onmessage or addEventListener( message ...) ] -> Ajax Handler on client? vs... XHR (request) (response) (current)
if you had a system that was _polling_ eg. open a worker, make xhr requests in a loop forever, on each response, postMessage() the results back to the client, then you can benefit
- We can't create _real_ workers in IE6, 7, 8 and 9 because a real Worker is actually an OS level thread that's capable of being spun up over multiple cores
eg. user A has a quad core, user B has dual core, they both visit a website that makes use of a Renderer (ie. the window) + 2 Workers, so 3 processes in all
- For A: Core 1: Renderer; Core 2: Worker; Core 3: Worker
- For B: Core 1: Renderer; Core 2: Worker; Core 1: Worker
so, thats the argument against those bogus "setTimeout" loops pretending to be Workers
- jQuery will throw dom security exceptions when run in WorkerGlobalScope because
window
anddocument
don't exist and jQuery explicitly refers to them
comment:5 Changed 12 years ago by
Yeah, $.ajax
is already quite asynchronous since the request and network activity happens in parallel with whatever is going on with JavaScript on the page. All that the web worker buys you is some extra parallelism in the JSON parsing and completion functions, but as rwaldron mentions you wouldn't be able to do any DOM operations there because of the security/thread-access restrictions. For that reason alone it's pretty much a non-starter.
You mentioned it would "surely improve performance", do you have any code examples?
We can table this for discussion in a later release since feature requests for 1.7 are closed, but I'm ok with seeing how much code it would take and how much performance would benefit.