-
Notifications
You must be signed in to change notification settings - Fork 193
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
Import workers from url #453
Conversation
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.
This looks great.
I am wondering if we should skip the Loader/WorkerLoader separation in v2?
A related thing that bothers me:
It would be great if we could support bundling the workers via an optional import path:
import {dracoWorker} from '@loaders.gl/draco/draco-worker-loader`;
import {DracoLoader} from '@loaders.gl/draco`;
import {registerWorkers} from `@loaders.gl/core`;
registerWorkers({
DracoLoader: dracoWorker
});
To handle dist/es*
we could add a 'src/draco-worker-loader`:
import `../draco-worker-loader`;
but that doesn't work with src
because we have two-level dist folders (dist/esm
) and one level src
folders, it is not possible to easily resolve @loaders.gl/draco/draco-worker-loader
in all cases.
@@ -56,7 +56,9 @@ test('ArrowLoader#parse (WORKER)', async t => { | |||
return; | |||
} | |||
|
|||
const data = await parse(fetchFile(ARROW_SIMPLE), ArrowWorkerLoader); | |||
const data = await parse(fetchFile(ARROW_SIMPLE), ArrowWorkerLoader, { | |||
workerUrl: 'modules/arrow/dist/arrow-loader.worker.js' |
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.
Nit: Add comment explaining why we override workerUrl. (I assume it is because we don't want to be CDN dependent in unit tests).
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.
If we fix a bug in the loader we need to test the local version, not the one already published to cdn.
worker | ||
worker: true, | ||
defaultOptions: { | ||
workerUrl: `https://unpkg.com/@loaders.gl/arrow@${__VERSION__}/dist/arrow-loader.worker.js` |
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.
Idea: Looks like these strings could be auto-deduced inside core based on a loader.id
or loader.package
field?
That way we could contain the proliferation of __VERSION__
and just handle it in core.
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.
This way it is possible for users to pass in a custom url pointing to their own server. I actually think this logic is easier to read than putting some complex resolution logic into the core.
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.
👍 completely agree that code should be optimized for clarity, and I do like the fact that this makes things so explicit.
However, still worth a discussion:
- I do find injected constants confusing (it can take reader quite a while to understand where
__VERSION__
is coming from. A one-line comment above each injection could solve that. - I usually end up having to deal with side effects from such injections in certain configurations. You already handle the test case via explicit overrides, but how about the
start-local
case? - What will
__VERSION__
be in that case, and is there a way for us to still override it in core without having more structural understanding of how these urls are formed?
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.
Added comment and fixed start-local
(inject __VERSION__: 'latest'
).
We could come up with smarter ways to deal with the local test scenario in the test harness. I prefer not to do it inside the core to avoid unintended implicit behavior.
edited my comment for readability |
What is the benefit to import worker from url? |
@georgios-uber This approach should allow you to load basis from a CDN. |
Updated PR summary. |
@ibgreen After this PR the worker loader is so light that I don't think it matters even if tree shaking does not work... |
Yes absolutely, once workers are dynamically loaded they should be available by default. I even think we should include the I made the comment based on the assumption that we still want to support applications that do not want to rely on potentially flaky ``https://unpkg.com` CDN, and would like to bundle their loaders. By providing an optionally importable worker and a registration mechanism to attach it to the Are you of a mind that CDN support is sufficient? |
If an user does not want to use CDN, the recommendation would be copying the worker source (included in dist/) to their own server as a static asset. Either way the worker would not be bundled with the main app (not desirable anyways for the large loaders). |
I feel that we are pushing some burden on the app developers by not having an intermediary option, but I agree that we can take that approach, at least for larger workers
In addition, the worker loaders are only half the story. We have big amounts of code in our non-worker loaders, and as long as we are including those we still have an issue with loader size:
Option: Dropping non-worker loaders completely
|
Discussed offline - merging for now, will address in follow up PRs:
|
Currently the
*WorkerLoader
s embed worker source as strings. This approach introduced the following issues:This PR is the first step towards addressing these issues:
*WorkerLoader
s and by default loaded from CDN. It significantly reduces the footprint of the worker loaders.