-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
adapter-cloudflare
seems to undo all code splitting, and worse
#2963
Comments
So, this seems to be because of the If bundling everything into the single file is the desired behavior, why are the js files from I cannot pass Next up, trying to use dynamic imports. |
Well, dynamic imports manage to split the dependency into its own |
This is how workers, well, work.
Everything in |
My understanding is that Cloudflare Pages does not bundle all the static html, images, etc into _worker.js (I think I heard it uses KV, but haven't seen that confirmed). It would be neat for _worker.js to import from this store too, instead of bundling, for large chunks. I was able to use a dynamic import with a wrapper component like this:
However, it seems this gets tricky to generalize:
|
adapter-cloudflare
seems to undo all code splitting, and worse
For posterity, that seemed to run
I wish this was easier to do without hardcoding the import in this wrapper (see earlier comment). |
on the same topic of In my case, it divides by 2 the worker size (~1.2MB => 600KB). EDIT: it appears that cloudflare does its own minification/gzipping when publishing, which explains why some big raw worker still end up being OK with the 1MB worker size requirement. |
I also stumbled across this problem.
It took me a while to even find the error for this. For me, the reason for my huuuge 6.4 MB As a workaround, I changed the import of my BabylonJS wrapper class from this: import BabylonViewer from "./BabylonViewer"; to this: onMount(async () => {
let BabylonViewer = await import("./BabylonViewer");
if (bjsCanvas) {
let viewer = new BabylonViewer.default(bjsCanvas);
}
}); But there really should be a better way to specify which dependencies should belong into the |
This comment was marked as spam.
This comment was marked as spam.
Here with a quick update:
We can update the cloudflare-workers adapter to not bundle first but the cloudflare adapter will need to wait. |
After trying to get a no bundle deployment working for a cloudflare workers project, I'm not seeing the benefits of it. It almost always increases the upload size / gzip size. cc: @dario-piotrowicz what are your thoughts on this? Relevant: We should however make it more apparent in the documentation (if it's not already) that importing a library into a |
I can imagine that bundling can reduce the size of a svelteKit app by doing some code optimization and also deduplication and whatnot (wrangler uses esbuild under the hood, which in turn can optimize things), so it's not extremely surprising to me that the app's size can decrease with bundling. But anyways, if there's a good amount of dynamic imports in the production build I would still strongly recommend to use no-bundling, as we've seen that that can significantly decrease response time (we do leverage that in our Next.js adapter) and runtime improvements in the module registry are in the work which would even increase the efficiency of this (cloudflare/workerd#1553).
What applications have you tried non-bundling with? I would assume that benefits would be very negligible for small hello-world applications but become much more significant as the complexity of the app and the number of dynamic imports increases. (Again, in our Next.js adapter, relying on no-bundling and dynamic imports basically made shipping large applications possible, applications which otherwise would fail the Cloudflare startup time limit validation). @eltigerchino these are my two cents on this 🙂 I would also try to figure out why you see an increase in the app's size and understand if that's negligible, how it scales and if that can be potentially addressed/improved on the SvelteKit's side In any case I am always here (and on discord) to help any way I can 😄 |
Thanks @dario-piotrowicz . I didn't realise it has a big impact on the start up time. In that case, should it be an option with the default as bundled? When I was doing some testing on this, I used a medium sized project on the free plan of cloudflare pages (https://brgh.church). Unbundled, the size would be 800KB+ and bundled would be 500KB+ uncompressed, both within the 1MB free plan limit when compressed. My incorrect assumption was the increased function size would affect the start up time but maybe being unbundled has a bigger benefit? |
mh... maybe, but ideally I think the best would be to just to with unbundled and try to reduce the app size as much as possible, to basically make it objectively better than the bundled version (but if that's not possible/desired adding an option could be a viable alternative)
mh... I see... yeah that doesn't seem a very minimal difference... but I think it would really be valuable to understand what those extra 300KB contain.... is it possible that those contain code that your build process fails tree-shake? (or even browser code?)
yes, unbundled should definitely have a smaller startup time, but again, it depends on how many lazy boundaries the code has and how much code those allow not to evaluate (and after cloudflare/workerd#1553 to parse and compile) |
Now that you mention it, it's very likely I didn't configure esbuild correctly while I was trying it out and that could be one of the reasons why. I was fiddling around to try and add Currently, the adapter uses esbuild with this worker file as the entry point, which imports the kit/packages/adapter-cloudflare/index.js Lines 72 to 92 in 41b7ae9
|
A related esbuild issue concerning unbundled support evanw/esbuild#708 (or maybe I’m thinking about this the wrong way? Do we even need esbuild if we’re not bundling code? Or maybe we just need to copy the server code over?) |
Describe the bug
I'm using cloudflare-adapter to deploy to Cloudflare Pages. My
_worker.js
is growing to ridiculous sizes, perhaps most relevantly, it's larger than my app with all its chunks!My biggest dependency is mapboxgl, and I see it minified in
.svelte-kit/cloudflare/**/_app/chunks/vendor-*.js
. But, I also see it embedded in.svelte-kit/cloudflare/_worker.js
. Why is it both split and not split?Reproduction
TBD
Logs
System Info
Severity
blocking an upgrade
Additional Information
This is severe because Cloudflare Workers
_worker.js
limit is only 1.5 MB, and importing mapboxgl without splitting uses a huge part of that.The text was updated successfully, but these errors were encountered: