-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
Add support for external workers in control CSP version #2130
Conversation
* ... Once `dist/maplibre-gl-csp.js` is loaded ... | ||
* maplibre.workers = workers; | ||
*/ | ||
workers: undefined as Array<WorkerInterface>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why undefined as...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why I added it. Updated code.
I'm a little skeptical of this PR. Given this motivation, the natural solution seems to be to preload (
|
Csp by definition is pushing things to the user. |
I disagree. The only thing required to be CSP-compliant is to have the worker script served from the same server as the UI entrypoint (rather than a data or blob url). So for instance, populate the worker url as |
@rotu, We have tried preloading and it did not worked for Workers. Here is a sample: https://perfmeasure.blob.core.windows.net/$web/maplibre_CSP_preload.html Here is the warning I see in console and also can see worker getting downloaded twice. I have tried setting Apart from this downloading issue, another reason to push creation of Worker ASAP is the time it takes the Worker to spin up after it's been initialized (Js compilation time and some other mysterious time). Regarding 'mysterious time', even if I initialize a worker and immediately post a message to it. Message is not received by the worker immediately after Js compilation is complete. So this change makes sure that by the time style is broadcasted to worker, its ready to receive it. This Change along with PR(#2131), allows styles to be processed in parallel majority of the time. We have tried with prewarm and were able to get styles processed in parallel only a small % of time. |
Yeah it seems browsers don't implement preload for script workers :-(. Does prefetch work instead? Does modulepreload work?
Absolutely. As soon as we know we need workers, we should be spinning them up - I don't think that means we should be creating workers outside of the library.
I'm not clear what you mean - is prewarm working or not? I think a |
#1 Prefetch also does not work. Just tried modulepreload, I don't see console warning with it, but network does show worker getting downloaded twice. #2. Spinning the worker outside the library gives us the best shot at having the worker ready ASAP, as it does not have to wait for Library. This is showing faster overall load performance on Bing maps, even faster than non-CSP version with prewarm. #3. Yes prewarm is working, buts it's just too late for the worker to be ready by the time main thread broadcast styles to it. Specially when |
If it’s getting downloaded twice, it sounds like you may have disabled your browser cache.
So what is prewarm doing if it’s not spinning up workers?
What is the point of prewarming if it the workers aren’t ready by the time we need them? I’m thinking that our implementation of prewarm is broken |
In looking into this more, our Worker implementation is very unsafe; the Definitely not the kind of thing we should be exposing in the public interface. |
I relooked into it and I did some synthetic testing on webpageTest comparing external workers vs prewarm and I am not seeing much difference ( with and without this PR) when using I will run a A/B test on Bing maps and will report back in about 2 weeks, to see if we still see any improvement with external worker (after applying Thanks again for your time. Will report back in 2 weeks. Here is the samples pages I tested |
Update. We ran a A/B test with and without this change. There was not a statistically significant gain seen in the metrics that we log. Abandoning this PR for now. Thanks for all your comments. |
Changes
Launch Checklist
CHANGELOG.md
under the## main
section.