Reduce size of web workers#372
Closed
simolus3 wants to merge 12 commits into
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This reduces the size of the default worker (
dart compile js -O4 example/worker.dartinsqlite3_web) from 278,943 characters JavaScript to 219,095; around 21% less.This relies on:
Uri.parse: We only useUrito represent worker/wasm assets which are then passed to JavaScript as a string, and throughpackage:path. By usingnew URLdirectly, we don't have to pull inUri.parseinto the worker.BigInt: DartBigInts are implemented in Dart. Parsing and formatting those values pulls in about 10kb of code in an-O4build. 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.jsifyanddartify: 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
utf8withTextEncoderandTextDecoder, 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.