Reduce monomorphization load of various functions #2143
Merged
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-lines
in our project that usesnapi-rs
extensively. 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 newReturn
generic 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_cb
this should be just as good on 3.x.