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

Reduce code size on latest Rust #1

Merged
merged 2 commits into from
Jan 21, 2021
Merged

Reduce code size on latest Rust #1

merged 2 commits into from
Jan 21, 2021

Conversation

RReverser
Copy link
Contributor

@RReverser RReverser commented Jan 21, 2021

A simple workaround for rust-lang/rust#74947 which made each indexing location include itself as a string in the final binary, resulting in a significant code bloat in case of hqx which generates a lot of indexing via macros.

Stats for a simple Wasm that reexports all 3 variants of HQX:

initial size: 462,076 bytes
Dst wrapper with unreachable!: 250,225 bytes
Dst wrapper with debug_unreachable!: 190,312 bytes

I'm open to removing debug_unreachable! in favour of just unreachable, but I was assuming that indexing code is well-tested and the extra difference seemed nice to have.

Workaround for rust-lang/rust#74947 which made each indexing location include itself as a string in the final binary, resulting in a significant code bloat in case of hqx which generates a lot of indexing via macros.

Stats for a simple Wasm that reexports all 3 variants of HQX:

initial size:                         462076 bytes
Dst wrapper with unreachable!:        250225 bytes
Dst wrapper with debug_unreachable!:  190312 bytes

I'm open to removing `debug_unreachable!` in favour of just `unreachable`, but I was assuming that indexing code is well-tested and the extra difference seemed nice to have.
hqx/src/common.rs Outdated Show resolved Hide resolved
@RReverser
Copy link
Contributor Author

Wow, I forgot how slow CIs other than Actions are 😀

@CryZe
Copy link
Owner

CryZe commented Jan 21, 2021

Haha, yeah same. I'll just merge once the first one of the current commit is finished. Which is apparently now.

@CryZe CryZe merged commit d7cbae6 into CryZe:master Jan 21, 2021
@RReverser RReverser deleted the code-size branch January 21, 2021 15:04
@RReverser
Copy link
Contributor Author

Thanks!

@RReverser
Copy link
Contributor Author

Can you please make a version tag too? I guess I could refer to a commit SHA, but it's not as pretty :)

@CryZe
Copy link
Owner

CryZe commented Jan 21, 2021

Alright, I tagged it as v0.1.3

@RReverser
Copy link
Contributor Author

Thanks!

RReverser added a commit to GoogleChromeLabs/squoosh that referenced this pull request Jan 21, 2021
I've played a bit and added a non-invasive change to the HQX - CryZe/wasmboy-rs#1 - to work around the code size regression (rust-lang/rust#74947) introduced in the latest Rust.

As a side benefit of the change, the build time also went down significantly and now takes only 1 minute altogether - including spawning Docker, fetching Cargo, building Wasm and optimising it with wasm-opt - instead of 15-20 minutes it took before.

P.S. h/t @CryZe for a very quick review & publish.
RReverser added a commit to GoogleChromeLabs/squoosh that referenced this pull request Jan 22, 2021
I've played a bit and added a non-invasive change to the HQX - CryZe/wasmboy-rs#1 - to work around the code size regression (rust-lang/rust#74947) introduced in the latest Rust.

As a side benefit of the change, the build time also went down significantly and now takes only 1 minute altogether - including spawning Docker, fetching Cargo, building Wasm and optimising it with wasm-opt - instead of 15-20 minutes it took before.

P.S. h/t @CryZe for a very quick review & publish.
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.

2 participants