-
Notifications
You must be signed in to change notification settings - Fork 111
Shrink the size of all Error
types
#225
base: master
Are you sure you want to change the base?
Shrink the size of all Error
types
#225
Conversation
#[doc(hidden)] | ||
pub $crate::State, | ||
); | ||
pub struct $error_name(pub Box<($error_kind_name, $crate::State)>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we can't pattern match on the kind (box
if nightly only), maybe we could remove pub
and put everything into $crate
as
struct ErrorInternals<K> {
kind: K,
backtrace: Backtrace,
next: ...
}
I tried that at one time, but it was rejected because it prohibited the use of pattern matching. But if we can't use it anyway...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in the usage I've seen I think it's quite important to match on ErrorKind
, but is matching on the entire error itself that important?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes : https://github.com/rust-lang-nursery/error-chain/blob/master/src/lib.rs#L348-L353
With the new method, you can't do that anymore. You have to match on Result, then on error.kind().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong link. Adding #226
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, yes.
Nice! You just have to update the tests which use pattern matching on the kind. It's also a breaking change so could you update the CHANGELOG? |
26e98c6
to
f9c26a0
Compare
Updated |
f9c26a0
to
23586d7
Compare
Could you rebase please? |
This commit improves the in-memory size of `Error` from 7 pointers to 1 pointer. Errors are in general relatively rare in applications and having a huge error type ends up generating lots of instructions for moves and such, so this PR optimizes for size and passing around errors rather than creating errors.
23586d7
to
f3020b8
Compare
Sure thing, done now |
ErrorKind::Msg(_) => {} | ||
_ => {} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very satisfied with this new behaviour, it's less straightforward. Not sure how to improve it though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
box_patterns will be stabilized some day, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yamakaky do you have a preferred method of how we might land this? I'd personally like to see this as at least an option, it's what I'd want for libraries 99% of the time I believe.
When might this pull request be land/be merged? |
This commit improves the in-memory size of
Error
from 7 pointers to 1 pointer.Errors are in general relatively rare in applications and having a huge error
type ends up generating lots of instructions for moves and such, so this PR
optimizes for size and passing around errors rather than creating errors.