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

schema-wasm: optimize for -Oz with LLVM and Binaryen #4449

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aqrln
Copy link
Member

@aqrln aqrln commented Nov 15, 2023

This PR explores how much size can be trivially saved in WASM binaries
compared to how we currently build them, using prisma-schema-wasm as
the example. This is not necessarily useful for prisma-schema-wasm
but could be useful for the QE.

  • Enable more aggressive size optimization level in LLVM (z instead of
    s) at some runtime performance cost.
  • Further optimize the WASM binary for size using wasm-opt from
    Binaryen.
optimization level size ratio
-Os (baseline) 2742189 100%
-Oz 2558271 93.29%
-Oz + wasm-opt -Oz 2081699 75.91%

This PR explores how much size can be trivially saved in WASM binaries
compared to how we currently build them, using `prisma-schema-wasm` as
the example. This is not necessarily useful for `prisma-schema-wasm`
but could be useful for the QE.

- Enable more aggressive size optimization level in LLVM (`z` instead of
  `s`) at some runtime performance cost.
- Further optimize the WASM binary for size using `wasm-opt` from
  Binaryen.

| optimization level     | size    | ratio  |
| ---------------------- | ------- | ------ |
| `-Os` (baseline)       | 2742189 | 100%   |
| `-Oz`                  | 2558271 | 93.29% |
| `-Oz` + `wasm-opt -Oz` | 2081699 | 75.91% |
@aqrln aqrln requested a review from a team as a code owner November 15, 2023 13:32
@aqrln aqrln requested review from Weakky, Druue and jkomyno and removed request for a team November 15, 2023 13:32
@aqrln aqrln marked this pull request as draft November 15, 2023 13:37
@aqrln
Copy link
Member Author

aqrln commented Nov 15, 2023

Marking as draft to make it explicit that it's just a random experiment, not necessarily intended to be merged unless we decide we actually want to do this and have confirmed that performance is acceptable.

Copy link
Contributor

@Jolg42 Jolg42 left a comment

Choose a reason for hiding this comment

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

I think merging this would be great!
The main benefits that I see would be that

Copy link

codspeed-hq bot commented Nov 15, 2023

CodSpeed Performance Report

Merging #4449 will not alter performance

Comparing schema-wasm-optimize-for-oz-with-llvm-and-binaryen (fad616b) with main (e95e739)

Summary

✅ 11 untouched benchmarks

@aqrln aqrln self-assigned this Nov 15, 2023
@aqrln
Copy link
Member Author

aqrln commented Nov 16, 2023

Some other numbers from yesterday that I didn't post:

optimization level size ratio
-Os 2742189 100%
-Oz 2558271 93.29%
-Os + wasm-opt -Os 2380284 86.80%
-Os + wasm-opt -Oz* 2333130 85.08%
-Oz + wasm-opt -Oz 2081699 75.91%

* had to build a bit differently with wasm-bindgen before wasm-opt, otherwise wasm-bindgen was panicking, TODO submit a bug report

Next steps:

  • figure out the performance impact
  • maybe start with adding wasm-opt -Os without changing LLVM optimization level at first

@aqrln
Copy link
Member Author

aqrln commented Nov 16, 2023

Contributes to https://github.com/prisma/team-orm/issues/584

@janpio
Copy link
Contributor

janpio commented Jan 12, 2024

Removed from DA project based on feedback from Alberto+Serhii.

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.

3 participants