Reduce the size of Expression
#83
Open
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.
The
Expressiontype seems to have gotten quite large: it's currently 600 bytes. This PR reduces that to 240 bytes via the following:LicenseIdandExceptionIdnow only store the index. All the metadata is static so we can look it up as necessary.name,full_name, andflagshave been changed to getter methods to accommodate this. This brings their size down from 48 bytes to 8 bytes. Reducing the size of the index type is unlikely to bring any further benefit, since these types are stored in enums that have variants just as large.AdditionItemandLicenseItemhave been boxed, since I don't expect them to be very common. This bringsAdditionItemandLicenseItemdown from 56 bytes to 16. They could be 8 bytes if Rust learns to optimize them better. This in turn takesLicenseReqfrom 104 bytes to 32.Tuning the
SmallVeccapacity might be something to look into in the future; I suspect most Rust crates useMIT OR Apache-2.0and hence a capacity of 3 would work fine.