Repository navigation
feat: Wrap Error into a Box so it's size shrinks from 104 bytes to 8 bytes - #230
Conversation
2f41217 to
2b070db
Compare
|
I also think In the same vein we could remove |
Let's deprecate it for now. We could remove it few releases later. We have few other items deprecated in older versions (e.g. 0.11 and 0.15) which we could remove for 0.20! But in a separate PR. |
|
Shall I mark it as deprecated in this PR or do you also want that in a separate PR? |
This PR is OK! |
…o 8 bytes The size of a `Result` is as large as it's largest variant, thus `AvroResult` is currently always at least 104 bytes. Therefore, even if the function only returns a `usize` on success the function still needs to (stack) allocate 104 bytes. I've renamed the current `Error` enum to `Details`, and actually made it a bit bigger by unboxing `Schema` arguments. The new `Error` type is just a wrapper around a `Box<Details>`. To keep the code simple and make as few changes as possible, I've added a construction function for every variant of `Details`. I've also changed any `ok_or(Error...`) to an `ok_or_else(Error...` as constructing the type is now "expensive" because it does an allocation. This is a breaking change if the user is matching on the error type. The fix is easy as the user can use `details` or `into_details` to get the inner `Details` to match on. When the user is constructing a struct-like variant of the type this is also a breaking change. This can be fixed by changing the curly braces to round brackets and removing the item names.
2b070db to
b8be1fe
Compare
|
I've marked |
|
@Kriskras99 I have no other comments on the PR! |
Supersedes/Closes #229.
The size of a
Resultis as large as it's largest variant, thusAvroResultis currently always at least 104 bytes. Therefore, even if the function only returns ausizeon success the function still needs to (stack) allocate 104 bytes.I've renamed the current
Errorenum toDetails, and actually made it a bit bigger by unboxingSchemaarguments. The newErrortype is just a wrapper around aBox<Details>.To keep the code simple and make as few changes as possible, I've added a construction function for every variant of
Details. I've also changed anyok_or(Error...) to anok_or_else(Error...as constructing the type is now "expensive" because it does an allocation.This is a breaking change if the user is matching on the error type. The fix is easy as the user can use
detailsorinto_detailsto get the innerDetailsto match on. When the user is constructing a struct-like variant of the type this is also a breaking change. This can be fixed by changing the curly braces to round brackets and removing the item names.