workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

perf(worker-rust): Add `dev` env for faster local build times

Open futile opened this issue 1 year ago • 8 comments

What this PR solves / how to test:

Add a dev-environment to wrangler.toml which builds with worker-build --dev instead of worker-build --release. This makes build times for local development much faster.

Add opt-level = "s" to Cargo.toml so release builds are optimized for size.

Remove the deprecated --local parameter from the wrangler invocation.

Author has addressed the following:

Not sure which of these I should do (and how).

  • Tests
    • [ ] Included
    • [x] Not necessary because: basic configuration change in a template
  • Changeset (Changeset guidelines)
    • [ ] Included
    • [x] Not necessary because: we don't have changesets for templates??
  • Associated docs
    • [ ] Issue(s)/PR(s): do we need to update some docs??
    • [ ] Not necessary because:

futile avatar Feb 20 '24 12:02 futile

⚠️ No Changeset found

Latest commit: 75114c5a4f32b2a07628517e47055f35562136de

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

changeset-bot[bot] avatar Feb 20 '24 12:02 changeset-bot[bot]

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7973227046/npm-package-wrangler-5059

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5059/npm-package-wrangler-5059

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7973227046/npm-package-wrangler-5059 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7973227046/npm-package-create-cloudflare-5059 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7973227046/npm-package-cloudflare-kv-asset-handler-5059
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7973227046/npm-package-miniflare-5059
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7973227046/npm-package-cloudflare-pages-shared-5059
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7973227046/npm-package-cloudflare-vitest-pool-workers-5059

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240129.3
workerd 1.20240129.0 1.20240129.0
workerd --version 1.20240129.0 2024-01-29

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

github-actions[bot] avatar Feb 20 '24 12:02 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.38%. Comparing base (01e0846) to head (75114c5). Report is 48 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5059      +/-   ##
==========================================
+ Coverage   70.34%   70.38%   +0.04%     
==========================================
  Files         298      298              
  Lines       15463    15463              
  Branches     3966     3966              
==========================================
+ Hits        10877    10884       +7     
+ Misses       4586     4579       -7     

see 6 files with indirect coverage changes

codecov[bot] avatar Feb 20 '24 12:02 codecov[bot]

Thanks for the review! One thing I'm not sure about: Removing the --local flag. This might fail with older wrangler-versions now, I think? Should I remove it again from this PR?

But then again, this template will probably be used with more recent versions of wrangler (since a template is usually used for new projects), so it might just be fine in this case.

futile avatar Feb 26 '24 12:02 futile

Wrangler 3, when the change to default to local mode occurred, has been out for ~9 months, so personally I wouldn't be too concerned about the change

Skye-31 avatar Feb 26 '24 12:02 Skye-31

Awesome, thanks! :)

futile avatar Feb 26 '24 12:02 futile

Do we need to update some docs somewhere to match this change?

petebacondarwin avatar Feb 26 '24 15:02 petebacondarwin

One other point I realized: Is opt-level = "s" for release-builds desired by default? Since it won't be running in the frontend/not downloaded by browsers, maybe this doesn't actually make that much sense?

I added it originally because it's a very common optimization for wasm use-cases, but maybe that doesn't really count for workers.

futile avatar Feb 26 '24 15:02 futile

I'm no Rust specialist so I would bow to your (or anyone else's views) but I would note that Workers still have a size limit on what can be deployed. So it might be worth keeping a size optimisation turned on?

petebacondarwin avatar Mar 07 '24 13:03 petebacondarwin

I'm no Rust specialist so I would bow to your (or anyone else's views) but I would note that Workers still have a size limit on what can be deployed. So it might be worth keeping a size optimisation turned on?

That's a good point. I think optimizing for size by default should be sensible for wasm-builds (like in this case), and users can still change/adapt this later on anyways.

So if it's up to me I would keep the opt-level = "s", but feel free to let me know if I should change it :)

futile avatar Mar 07 '24 20:03 futile

That seems reasonable to keep IMO

Skye-31 avatar Mar 07 '24 21:03 Skye-31