Skip to content
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

feat(query-engine-wasm): Decrease gzipped Wasm size to 1.3MB #4530

Closed
wants to merge 185 commits into from

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Dec 7, 2023

This PR contributes to https://github.com/prisma/team-orm/issues/584. This PR depends on #4466.

Before this PR, the gzipped @prisma/query-engine-wasm was 1.7MB.

  • b5b8e21 reduced the bundle size to 1.6MB:
    === Tarball Contents === 
    946B   README.md           
    355B   package.json        
    28.5kB query_engine_bg.js  
    4.3MB  query_engine_bg.wasm
    4.7kB  query_engine.d.ts   
    538B   query_engine.js     
    === Tarball Details === 
    name:          @prisma/query-engine-wasm 
    package size:  1.6 MB                                  
    unpacked size: 4.3 MB
    
  • 8e8c520 reduced the bundle size to 1.3MB:
    === Tarball Contents === 
    946B   README.md           
    355B   package.json        
    28.5kB query_engine_bg.js  
    3.3MB  query_engine_bg.wasm
    4.7kB  query_engine.d.ts   
    538B   query_engine.js     
    === Tarball Details (gzip) === 
    name:          @prisma/query-engine-wasm   
    package size:  1.3 MB                                  
    unpacked size: 3.3 MB
    

Miscellaneous

Passing the --reference-types option to wasm-pack build, or the --remove-non-js-ops option to wasm-opt results in runtime errors when running the example. Reference types in particular would be good to have, as they would likely improve the CPU performance of @prisma/query-engine-wasm.

jkomyno and others added 30 commits November 10, 2023 13:49
…github.com:prisma/prisma-engines into feat/sql-query-connector-on-wasm32-unknown-unknown
Miguel Fernández and others added 13 commits December 5, 2023 15:09
* qe-wasm: Partially fix the test suite

1. Bash script for build did not abort on error, hence sed error on
   linux went unnoticed.
2. We don't actually need sed trickery sincce `wasm-pack` has a flag for
   changing binary name.
3. `tracing` feature does not actually work on WASM even partially: it panics on
   `Instant` invokation as soon as first span is created. Since we are
   running tests with all preview features enabled, that means that
   practically any test panics now. Disabled it again.

A lot of tests are still failing on ThreadRng invocation and stacktrace
is not really helpful, but I still think it's better if we get it
working.

* Update query-engine/query-engine-wasm/build.sh
@jkomyno jkomyno added this to the 5.8.0 milestone Dec 7, 2023
@jkomyno jkomyno self-assigned this Dec 7, 2023
@jkomyno jkomyno changed the title feat(query-engine-wasm): Decrease Wasm size feat(query-engine-wasm): Decrease Wasm size to 1.3MB Dec 7, 2023
@jkomyno jkomyno changed the title feat(query-engine-wasm): Decrease Wasm size to 1.3MB feat(query-engine-wasm): Decrease gzipped Wasm size to 1.3MB Dec 7, 2023
@jkomyno jkomyno marked this pull request as ready for review December 7, 2023 09:59
@jkomyno jkomyno requested a review from a team as a code owner December 7, 2023 09:59
@jkomyno jkomyno requested review from miguelff and Druue and removed request for a team December 7, 2023 09:59
Copy link

codspeed-hq bot commented Dec 7, 2023

CodSpeed Performance Report

Merging #4530 will not alter performance

Comparing feat/wasm-decrease-size (8e8c520) with feat/query-engine-wasm32-unknown-unknown (14ceb7c)

Summary

✅ 11 untouched benchmarks


[package.metadata.wasm-pack.profile.release]
wasm-opt = [
"-Oz", # super focus on code size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much do we win on -Oz comapring to -Os? Last time we looked into it, size win was quite marginal but performance hit was quite big. I'd rather us do this flag separately, when we are ready to run the benchmarks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIth -0s, we'd have:

946B   README.md           
355B   package.json        
28.5kB query_engine_bg.js  
3.4MB  query_engine_bg.wasm
4.7kB  query_engine.d.ts   
538B   query_engine.js     
=== Tarball Details === 
name:          @prisma/query-engine-wasm 
package size:  1.3 MB                                  
unpacked size: 3.4 MB

So, still 1.3MB. At some point we'll need to re-run the benchmarks to ensure we aren't optimising too much for size while worsening the performance.


[package.metadata.wasm-pack.profile.release]
wasm-opt = [
"-Oz", # super focus on code size
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"-Oz", # super focus on code size
"-Os", # focus on code size

Base automatically changed from feat/query-engine-wasm32-unknown-unknown to main December 8, 2023 09:03
@jkomyno
Copy link
Contributor Author

jkomyno commented Dec 11, 2023

This PR is deprecated by #4552.

@jkomyno jkomyno closed this Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants