-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add keep-error-msg feature #740
base: master
Are you sure you want to change the base?
Add keep-error-msg feature #740
Conversation
This is the sort of thing for which you should have created an issue first. Are you using |
I'm using object directly for a PE resolver, and I noticed there are useless strings in the binary that is unused which cannot be eliminated by DCE |
So can I infer that the answers to my other questions are you are only using the How many bytes does this save you, and how large is your image? A feature like this doesn't come without cost in terms of usability. For example, all existing users that use |
Yes, at the moment I'm only using the My guts feeling tells me that we should make those error message categorized as enum so we can better inline it (in other word, like string intern). |
I haven't looked at the code generation, but my instinct is there should be little overhead for
Yes, I think it's a better option than a feature, but I'm not sure it's not going to be a huge difference in code size (potentially changes from a 128-bit slice pointer, to a |
Because Rust requires you to construct the whole object (that includes everything even if you don't need it) in order to maintain compliant drop semantics, even if you don't use the error yourself. Now you also need to take in account for the extra code that constructs those objects as well, because LLVM is not going to smartly deduce your struct to become a ZST even if you don't use the &'static str or String at all, it has to be very conservative, and that's why it takes a lot more space and code than expected and makes a lot more savings.
We could use derive_more, and it also supports |
I still don't understand what you mean.
A downside of using an enum is that users who do want to print the errors will be forced to pull in the strings for every possible error, not just the ones they might encounter, so it's still a tradeoff. It's also more effort to write the code, since the error definition is separate from the code where the error occurs. There will need to be significant benefits to do any change in this area, and size reduction of 1k is not significant. |
This PR allows the user to remove the message embedded into each Error of the read/write/build crates, since Rust is terrible at removing dead code. The string will stay due to Error construction, which is effectively discarded, even if the user doesn't care about the error message (aka just want to have a boolean indicating error), which means precise ROM space wasted.