Repository navigation
Draft: feat: Shrink Error type by Boxing large types - #229
Closed
Kriskras99 wants to merge 1 commit into
Closed
Kriskras99 wants to merge 1 commit into
Kriskras99 wants to merge 1 commit into
Conversation
martin-g
marked this pull request as draft
July 18, 2025 06:14
Shrinks the type from 104 bytes to 32 bytes.
Kriskras99
force-pushed
the
feat/smaller_error
branch
from
July 19, 2025 14:31
6ebb30b to
76009e5
Compare
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.
This PR shrinks the error type by 32 bytes to 72 bytes, saving 32 bytes of stack/registers for every function returning a
Result<_, Error>. The new largest variant isGetDefaultRecordFieldat 72 bytes.This is still quite large, but I'm not sure how to change
GetDefaultRecordField. The thirdStringcan be aBox<Schema>which would shrink it to 64 bytes but would require rewriting a few tests. Another option is making itBox<String>, Box<String>, Box<String>which is 24 bytes (orBox<str>, Box<str>, Box<str>which is more idiomatic but is 48 bytes).@martin-g feel free to add commits to this PR to shrink more types.
Distribution of the size of
Result::Ok:Note: this is a distribution of the size of
Result::Ok, not how often it is used.(Almost) all of the types with the Error type
Note: I temporarily renamed the Error type to AvroError to make it easier to grep for.Old:
-Zprint-type-sizes output for the Error type
From
RUSTFLAGS=-Zprint-type-sizes cargo +nightly build --release > types.txtNew:
-Zprint-type-sizes output for the Error type
From
RUSTFLAGS=-Zprint-type-sizes cargo +nightly build --release > types.txt