-
Notifications
You must be signed in to change notification settings - Fork 111
Memory bloat #44
Comments
@kali has made a very interesting overview over the origin of the 56 bytes: #45 (comment) |
This doesn't seem like a great comparison - |
Regardless of whether And about io::Result: |
OK but you've used a type which has 0 bytes of data for the non-discriminant portion. All you've documented is that the largest variant of the null error chain is 55 bytes. That doesn't mean that the equivalent of |
Not really an issue, closing. |
This is a pretty major issue of this crate, as its against the "performance speed ease of use pick three" motto of Rust, by improving ease of use by heavily impairing performance. |
The solution would be to make the |
If we assume that errors are less likely than the happy path, we can optimize the memory footprint for the happy path if we heap-allocate most of the error payload. If we look at But on the other hand there may be situations where such heap allocations are not desirable, e.g. (i) when errors happen frequently or (ii) when compiling with So maybe |
Hum, interesting. Any idea for a the syntax? |
I think the first question is: do you want this behavior to be controlled by syntax in the macro invocation, or by a crate feature? A crate feature would be easier to implement & IMO probably easier to use (less new syntax to learn), but wouldn't allow you to scope the behavior to an individual invocation. I'm not sure how often people are defining multiple error_chains in their crate, much less they have a need to different performance properties between them. |
A crate feature would be enough for me, too. Anything that makes the memory footprint smaller :) |
I think you could start with a crate feature. That should be sufficient in most cases. A syntax could still be introduced later if there is demand and the crate feature would then only set the default behaviour. |
Someone correct me if we don't guarantee this yet, but I think if you box the error, |
I started the implementation with the feature, but I get errors like |
@Yamakaky Have you tried implementing Edit: Looking at all the impls for the error type, you probably will need a tuple struct, because some of them like |
Oh, cool! |
Please review #69 |
|
Awesome! |
Is there still work to be done on this issue? |
Was this feature implemented? If not, why it was abandoned? |
Honestly, I don't really work on a Rust project anymore, so I haven't been working on error-chain for some time... |
The code (basing on the example from the readme)
outputs:
I might be wrong, but isn't
ChainResult
just "yet another enum", which means those 55 extra bytes have to be copied over when returning, even in the success event? That would mean quite a performance overhead over normal Result in hot code, especially where only the Ok case which may be minimal is encountered, no?Maybe the situation can be improved by making the backtrace functionality optional, as in possible to opt out of at compile time?
The text was updated successfully, but these errors were encountered: