-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ServiceWorker: restructure data structure and algorithms to better match the spec #26108
Comments
Ok I've taken a closer look at this, and although I'm still figuring a few things out, it appears to me that the goal of this issue is not so much to use a For example the concept of a scope-to-registration-map), to me it appears this should be unique across the UA, in other words if different pages running in different Currently we partition this map per servo/components/script/script_thread.rs Line 534 in 7b5ec99
For example: In Register, we probably want to:
So this is I think also about making a difference between DOM concepts like So for example there can be multiple DOM objects pointing to the same "thing", like a running worker or a registration(each environment can only have one DOM For example compare a environment-settings-object-service-worker-registration-object-map with the "scope-to-registration-map" mentioned above. The first thing is on a "per environment setting(read The first one represents a map of So what we currently have on the script-thread, and which should be moved to the global, is actually this "environment-settings-object-service-worker-registration-object-map", and what we're missing is the "scope-to-registration-map", which belongs on the constellation, or perhaps rather the service worker manager for an origin. This requires some more looking into, and hopefully it can be broken up cleanly in issues or PR, but it could also get a bit messy... |
@gterzian is there anything I can work on for this meta issue 👀 ? |
@CYBAI I think there will be lots of things to do but I'm sure what yet, currently still looking at the spec and the code. I'm pretty sure we need to move the JobQueue operations to run on the constellation or service worker manager for an origin, and callback into script where necessary, and have a bunch of data on the constellation or sw manager that would match various DOM objects(similar to what was done with MessagePort and BroadcastChannel), but its not completely clear to me yet. I also don't know how to break it up into issues yet, but I'll try to do so. Perhaps I'll start with some initial restructuring that opens the way for similar work on top of it... |
@gterzian Thanks! I will read the spec and code first! |
By the way, this sort of confirms that the Job queue should be somewhere at the constellation or service worker manager level(probably the latter) w3c/ServiceWorker#1224 |
Ok here is a bit of an action plan for this:
@jdm could you please let me know what you think of this? |
Sounds reasonable! |
This is a good write-up on the ServiceWorker architecture in Chromium: https://chromium.googlesource.com/chromium/src/+/lkgr/content/browser/service_worker/README.md#renderer-process Where you see written the "Browser process", you can substitute with the "Constellation and the ServiceWorkerManager", while the "Renderer process" is what happens in |
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
ServiceWorker: restructure Job Queue, Register flow, to better match spec <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #26108 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
EDIT: the second comment is more accurate, still keeping this here for a basic overview of how it currently works. We need to move the Jobqueue to the constellation or service worker manager level.
servo/components/script/serviceworkerjob.rs
Line 102 in f7d3d4a
Spec: https://w3c.github.io/ServiceWorker/#dfn-job-queue
The
JobQueue
used to run algorithms for service workers seems to currently be tied to having aScriptThread
being available.See for example how a job is scheduled:
servo/components/script/serviceworkerjob.rs
Line 110 in f7d3d4a
Or how a job is run:
servo/components/script/serviceworkerjob.rs
Line 139 in f7d3d4a
So I assume this only works in the context of a window
GlobalScope
.Since all the service workers IDL interfaces are also available to workers, I think we should try to make the job queue also work for a worker global.
We could try to do something similar as what is done with the
MicrotaskQueue
,servo/components/script/dom/globalscope.rs
Line 196 in f7d3d4a
which is available on the
GlobalScope
in addition to being available on theScriptThread
, so that worker event-loops can also use it.servo/components/script/dom/abstractworkerglobalscope.rs
Line 147 in f7d3d4a
Although to prevent a problem like #20908 we could try to just move the job queue entirely onto the global, and remove it from the script-thread, so functions like
run_job
andschedule_job
could be made to take a&GlobalScope
instead of a&ScriptThread
.The text was updated successfully, but these errors were encountered: