Eliminate closures capturing needlessly many type parameters #2821
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.
Closures capture every type parameter that is in scope, even ones which cannot make a difference to the behavior of the closure. This was previously causing a whole new MapDeserializer to be monomorphized for every distinct Visitor type that we deserialize from Content or &Content (i.e. internally tagged and untagged enums).
Tested by measuring the size of the rlib produced from the following small library.
cargo clean && cargo build --release && ls -l target/release/librepro.rlib
Before this PR: 127K. After this PR: 111K. This is 12% smaller.