-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Hides default fns inside Fuse impl to avoid exposing it to any crate #70910
Conversation
…IteratorImpl to avoid exposing default functions outside of the current crate.
Oh also, I just submitted this to understand if my logic is correct. In case you think it's good, don't approve / merge yet. I'll add a few comments for others stumbling across this in the future and then it can be merged. Didn't want to do that yet in case my implementation logic was wrong |
Added WIP to the title so it doesn't get merged, when you are ready you can remove it |
Cool. Does the WIP mean it won't get reviewed? Cuz I want it to get reviewed before I can make further changes. |
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.
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 0a54a94 with merge 99ca7e89f078ee57814d4b9c5575f84f2a2d2329... |
☀️ Try build successful - checks-azure |
Queued 99ca7e89f078ee57814d4b9c5575f84f2a2d2329 with parent 93dc97a, future comparison URL. |
Finished benchmarking try commit 99ca7e89f078ee57814d4b9c5575f84f2a2d2329, comparison URL. |
Removed unnecessarry empty impls. Moved code to organise it better
@cuviper a couple of questions:
PS, changes from my side are done. You can merge it away if you think this is good to go |
@cuviper sorry to bother you again, but did you get a chance to review this PR? |
You could make an iterator that counts how many times struct Foo<'a>(&'a mut usize);
impl Iterator for Foo<'_> {
type Item = ();
fn next(&mut self) -> Option<()> {
*self.0 += 1;
None
}
}
fn main() {
let mut counter = 0;
let mut foo = Foo(&mut counter).fuse();
for _ in 0..10 {
foo.next();
}
dbg!(counter);
} This will print impl std::iter::FusedIterator for Foo<'_> {} Then it will print If you'd like to turn that into explicit tests, with and without
It should be trivially inlined, yes, but that is more work for compilation time -- so I'm not surprised that the perf results show a little bit of a slowdown.
Well, before assembly there's also LLVM IR, so you could stare at that instead. 🙂 But without even bothering at the instruction level, you could just look at what functions are emitted. If there's no explicit function for the new impl layers, then those must have been inlined. Beyond that, I think you'd have to have a concrete example to compare assembly before and after. The optimizer can do surprising things -- in the above playground, after optimization it's flattened entirely into |
@Centril, since it was your request to internalize this, how do you feel about the slightly worse perf results? |
@cuviper Hmm; do you know where the regressions are coming from (I haven't checked the diff)? They don't look egregious, so imo correctness comes first in this case, but I wonder if we could have our cake and eat it too? |
Nothing stands out to me -- but just intuitively, there's an extra layer of function calls that have to be inlined away. Even in debug mode, it's simply a little bit more code to compile.
Well, we had chatted about a new language feature like |
Ah OK. :) My personal view is that, for now, we should accept the slight regression here, merge the PR, and try to recover it when we can do so in a correct way. |
@bors try @rust-timer queue |
@rakshith-ravi: 🔑 Insufficient privileges: not in try users |
Insufficient permissions to issue commands to rust-timer. |
Gah! |
I don't expect performance will be much different than before, but we can try it. @bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit abe5973 with merge 26002ac6b8bee06e3c810c453f5771d8b523b1da... |
☀️ Try build successful - checks-azure |
Queued 26002ac6b8bee06e3c810c453f5771d8b523b1da with parent 835428c, future comparison URL. |
FYI: We just deployed a PR to the perf collector that in theory reduces noise, but may also introduce other unexpected effects. If the results are odd or otherwise unexpected, it may be worth re-running the try build and the perf run. (Indeed, I would likely recommend just doing so regardless, but up to you). |
Finished benchmarking try commit 26002ac6b8bee06e3c810c453f5771d8b523b1da, comparison URL. |
Wait, the CPU cycles has reduced by 10%?!? And the number of instructions have reduced by 20%?!? Is this because of the new PR @Mark-Simulacrum? I mean, I had a hunch that the perf would increase with my new changes, but not this much xD |
We've seen improvements elsewhere, so it's most likely spurious, but let's try it again: @bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit abe5973 with merge 6524bc32a6a2b550d6fbbb229227b9f5a3cfd876... |
☀️ Try build successful - checks-azure |
Queued 6524bc32a6a2b550d6fbbb229227b9f5a3cfd876 with parent 534a41a, future comparison URL. |
The new performance results look pretty tightly neutral -- which is a good thing! @bors r+ rollup |
📌 Commit abe5973 has been approved by |
Rollup of 7 pull requests Successful merges: - rust-lang#70578 (Add long error explanation for E0657) - rust-lang#70910 (Hides default fns inside Fuse impl to avoid exposing it to any crate) - rust-lang#71164 (reword Miri validity errors: undefined -> uninitialized) - rust-lang#71182 (Add some regression tests) - rust-lang#71206 (Miri error messages: avoid try terminology) - rust-lang#71220 (Dogfood or_patterns in the standard library) - rust-lang#71225 (Fix typo in Default trait docs: Provides -> Provide) Failed merges: r? @ghost
Fixes #70796
@cuviper I've added some default, private traits to do the job for us. If required, I can expose them to a specific visibility if you want to call these functions for #70332
r? @cuviper