Reduce monomorphization load of various functions#2143
Merged
Brooooooklyn merged 4 commits intonapi-rs:mainfrom Jun 18, 2024
Merged
Reduce monomorphization load of various functions#2143Brooooooklyn merged 4 commits intonapi-rs:mainfrom
Brooooooklyn merged 4 commits intonapi-rs:mainfrom
Conversation
Outside of `std::panicking::try` and `tokio`, these functions were the highest-up in `cargo-llvm-lines`. Moves most of the logic out into non-generic functions.
Brooooooklyn
added a commit
that referenced
this pull request
Jun 25, 2024
* refactor(napi): reduce monomorphization load of `JsObject::{get, set}`
Outside of `std::panicking::try` and `tokio`, these functions were the highest-up in `cargo-llvm-lines`.
Moves most of the logic out into non-generic functions.
* refactor(napi): reduce monomorphization load of `JsDeferred::new`
* refactor(napi): reduce monomorphization load of `call_js_cb`
---------
Co-authored-by: LongYinan <lynweklm@gmail.com>
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.
Outside of the stdlib and
tokio, these functions were the highest-up incargo-llvm-linesin our project that usesnapi-rsextensively. These changes aim to reduce the amount of generated code (and hopefully also improve compile times because of it).Before:
After:
After these changes, outside of
napi::tokio_runtime::execute_tokio_future::{{closure}}there is no napi anymore in the top ~40 functions with the most lines generated.Binary size savings in our project (release, fully-optimized build):
JsObject::{get, set}: 200 KiBJsDeferred::new: 60 KiBcall_js_cb: 140 KiB (though with the newReturngeneric I wasn't able to outline as much in the 3.x version, so this might be lower now)In total, it saved ~120K LLVM lines.
Note that these changes were first done on napi 2.6, but I've ported them over to main. All size measurements were done on the 2.6 version, but other than a slightly less effective change on
call_js_cbthis should be just as good on 3.x.