Skip to content

feat(wrangler): add support for experimental code splitting - #9240

Closed
ItsWendell wants to merge 1 commit into
cloudflare:mainfrom
ItsWendell:feat/bundle-splitting
Closed

ItsWendell wants to merge 1 commit into
cloudflare:mainfrom
ItsWendell:feat/bundle-splitting

Conversation

@ItsWendell

@ItsWendell ItsWendell commented May 14, 2025 •

Copy link
Copy Markdown
Contributor

Implements #7344

Describe your change...

Add support for experimental code splitting for workers during build / deploy, this allows for dynamic imports and such await import("./module") to be code split using esbuid's built-in experimental code splitter. Optimizing performance of the worker, potentially memory-usage and worker startup time.

The following feature request clearly indicates benefits of having this: #7344

Resources:
https://esbuild.github.io/api/#splitting

Before:
Screenshot From 2025-05-14 14-49-56

After:
Screenshot From 2025-05-14 14-49-22


  • Tests
    • Tests included
  • Wrangler / Vite E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because:
  • Wrangler V3 Backport
    • TODO (before merge)
    • Wrangler PR:
    • [] Not necessary because:

@changeset-bot

changeset-bot Bot commented May 14, 2025 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dd8c646

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ItsWendell
ItsWendell force-pushed the feat/bundle-splitting branch 2 times, most recently from 219da67 to 170d3ed Compare May 14, 2025 12:27
@ItsWendell
ItsWendell marked this pull request as ready for review May 14, 2025 12:30
@ItsWendell
ItsWendell requested review from a team as code owners May 14, 2025 12:30
@ItsWendell
ItsWendell force-pushed the feat/bundle-splitting branch from 170d3ed to ec43022 Compare May 14, 2025 12:35
@ItsWendell ItsWendell changed the title feat(wrangler): add support for experimental bundle splitting feat(wrangler): add support for experimental code splitting May 14, 2025
@ItsWendell
ItsWendell force-pushed the feat/bundle-splitting branch from ec43022 to dd8c646 Compare May 14, 2025 12:53
@ItsWendell

Copy link
Copy Markdown
Contributor Author

@vicb would love to get your thoughts on this. Currently we load in the additional / code split modules exported by esbuild as modules right before we create the CfWorkerInit in deploy.ts, this could also happen in other places like in bundle.ts.

I'm unsure about properly resolving the source maps for these additional code split modules too, in an initial test that I ran, it isn't resolving properly, would love to get some pointers there too.

image

Where module-K2IBTMOL.js (module.ts) is a dynamic (local) module I imported and executed (and threw an error in).

    runAction = await import("./module");
    runAction.default();

@vicb

vicb commented May 15, 2025

Copy link
Copy Markdown
Contributor

Add support for experimental code splitting for workers during build / deploy, this allows for dynamic imports and such await import("./module") to be code split using esbuid's built-in experimental code splitter. Optimizing performance of the worker, potentially memory-usage and worker startup time.

The following feature request clearly indicates benefits of having this: #7344

I commented on the linked feature request.

We probably do not want to add code (test and maintenance burden) if there is no clear pros.

@vicb vicb added awaiting-response:reporter Awaiting response from OP for further clarification package:wrangler Relating to the `wrangler` package labels May 15, 2025
@ItsWendell

Copy link
Copy Markdown
Contributor Author

Fair enough, I didn't realize that in cloudflare/workerd#2372 someone ran a benchmark for code / bundle split workers / pages, and that work needs to happen still to improve performance there.

It sounds like it would still be beneficial to have those perf optimizations in workerd, but until that time, this PR is less relevant!

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 15, 2025
@lrapoport-cf lrapoport-cf added awaiting-response:cloudflare Awaiting response from the workers-sdk maintainer team and removed awaiting-response:reporter Awaiting response from OP for further clarification labels Jul 21, 2025
@vicb

vicb commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

Closing this until we start working on the feature request (#7344) when the new module registry is around.

@vicb vicb closed this Jul 21, 2025
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-response:cloudflare Awaiting response from the workers-sdk maintainer team package:wrangler Relating to the `wrangler` package

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants