-
Notifications
You must be signed in to change notification settings - Fork 14k
Disable inlining of packed io::Error destructor
#149146
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
Open
kotauskas
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
kotauskas:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
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.
Pondering: why is this the correct one to
inline(never)? What if we madedecode_reprbeinline(never)and allowed inlining the destructor as that turns into just a call todecode_repr?Said otherwise, if this drop is a problem, wouldn't
dataanddata_mutand such also not want this inlining?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.
decode_repris a generic function in whichCcan be one of&Custom,&mut Custom, orBox<Custom>. In the case of the references, which are instantiated bydataanddata_mut, no types with destructors are involved and there are no destructors to shuffle around. In theBox<Custom>case, which is what's called by the destructor ofRepr,decode_reprreturns ownership of that which needs its destructor called and never calls any destructors itself, meaning that putting#[inline(never)]on it and removing it fromRepr::dropwould just make the destructor get inlined again (except the code bloat would be even worse because the branching would get duplicated).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.
The ideal thing would be to ensure
ErrorData's drop is outlined but only when it has a nontrivial drop, right? I was thinking this could be done with something like:But from a quick check it seems like the
matches!check is outlined, despite the#[inline(always)], which completely defeats the purpose.The current optimization is kind of weird for this too. Looking at your godbolt link, it seems like it decides to inline the first drop and outline the second drop? Interesting heuristics.
Uh oh!
There was an error while loading. Please reload this page.
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 do think it's worth double checking whether there is an option to get this behavior in more places the nontrivial drop may happen, as Scott mentioned. But if there doesn't seem to be a good way, I don't see any reason not to make this change given the perf results.
What is the result without any
#[inline]/#[inline(never)]btw? Seems like that could give it some flexibility.