Skip to content

Reduce size of web workers#372

Closed
simolus3 wants to merge 12 commits into
mainfrom
smaller-workers
Closed

Reduce size of web workers#372
simolus3 wants to merge 12 commits into
mainfrom
smaller-workers

Conversation

@simolus3
Copy link
Copy Markdown
Owner

This reduces the size of the default worker (dart compile js -O4 example/worker.dart in sqlite3_web) from 278,943 characters JavaScript to 219,095; around 21% less.

This relies on:

  1. Not using Uri.parse: We only use Uri to represent worker/wasm assets which are then passed to JavaScript as a string, and through package:path. By using new URL directly, we don't have to pull in Uri.parse into the worker.
  2. Avoiding BigInt: Dart BigInts are implemented in Dart. Parsing and formatting those values pulls in about 10kb of code in an -O4 build. A worker doesn't create these values, it's only supposed to receive JS BigInts from messages and pass them through to the SQLite WASM file.
  3. Avoiding jsify and dartify: These methods are also fairly expensive as they have to walk through Dart objects. We only support binding a fixed set of types anyway, there's no reason we should have to send other values over the wire.

I've also experimented with replacing utf8 with TextEncoder and TextDecoder, but that ultimately isn't worth it. It saves around 5.5kb, but we mostly expect to convert short strings which is apparently cheaper to do in Dart.

simolus3 added a commit that referenced this pull request May 18, 2026
@simolus3 simolus3 closed this May 18, 2026
@simolus3 simolus3 deleted the smaller-workers branch May 18, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant