Skip to content
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 core::slice::Split::as_slice #92287

Merged
merged 1 commit into from
Apr 19, 2022
Merged

Conversation

JulianKnodt
Copy link
Contributor

This adds a remainder function to the Slice iterator, so that a caller can access unused
elements if iteration stops.

Addresses #91733

@rust-highfive
Copy link
Collaborator

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 26, 2021
@rust-log-analyzer

This comment has been minimized.

library/core/tests/slice.rs Outdated Show resolved Hide resolved
library/core/src/slice/iter.rs Outdated Show resolved Hide resolved
library/core/src/slice/iter.rs Outdated Show resolved Hide resolved
@the8472 the8472 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Dec 26, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 23, 2022
@camelid
Copy link
Member

camelid commented Mar 3, 2022

triage: What's the status of this PR?

@JohnCSimon
Copy link
Member

triage:
@kennytm this is still waiting on review fyi

@Dylan-DPC
Copy link
Member

r? @yaahc

@rust-highfive rust-highfive assigned yaahc and unassigned kennytm Apr 11, 2022
@yaahc
Copy link
Member

yaahc commented Apr 15, 2022

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 15, 2022
@JulianKnodt JulianKnodt requested a review from yaahc April 17, 2022 05:10
@rust-log-analyzer

This comment has been minimized.

@JulianKnodt JulianKnodt force-pushed the slice_remainder branch 2 times, most recently from 03c0d31 to 26fd042 Compare April 17, 2022 15:31
This adds a remainder function to the Slice iterator, so that a caller can access unused
elements if iteration stops.
@yaahc
Copy link
Member

yaahc commented Apr 18, 2022

Awesome, looks great. Thank you @JulianKnodt ^_^

@bors r+

@bors
Copy link
Contributor

bors commented Apr 18, 2022

📌 Commit 494901c has been approved by yaahc

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 18, 2022
@bors
Copy link
Contributor

bors commented Apr 18, 2022

⌛ Testing commit 494901c with merge d5ae66c...

@klensy
Copy link
Contributor

klensy commented Apr 19, 2022

Is there actually any reason to return empty slice if there is no elements left? Because in that case in next step we need to check is that slice empty on not.

Why not instead:

    pub fn as_slice(&self) -> Option<&'a [T]> {
        if self.finished { None } else { Some(&self.v) }
    }

P.S. currently function named as as_slice but PR's title and descriptions says about remainder.

@JulianKnodt
Copy link
Contributor Author

@klensy
From a purely performance perspective, it doesn't make sense to wrap an extra layer of Option around a slice since None here conveys the same thing as empty slice, the only possibility of difference would be if the iterator will return None but not been advanced, or if it has completed and returned None already.

If you convert it to None, you'd still have to check the tag of the enum, so there's no perf gain.

From a reader's point of view, I'm not sure it's semantically more clear to return an optional slice. From seeing it, I'd be surprised that it returned an optional slice, and not be sure when it would return None.

@bors
Copy link
Contributor

bors commented Apr 19, 2022

☀️ Test successful - checks-actions
Approved by: yaahc
Pushing d5ae66c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 19, 2022
@bors bors merged commit d5ae66c into rust-lang:master Apr 19, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 19, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d5ae66c): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 😿 relevant regressions found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 2 0 0 0
mean2 N/A 1.2% N/A N/A N/A
max N/A 1.2% N/A N/A N/A

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot added the perf-regression Performance regression. label Apr 19, 2022
@pnkfelix
Copy link
Member

Visiting for weekly performance triage.

The perf run says this regressed externs (a secondary benchmark) incr-full in debug and opt profiles by 1.2%

From my reading of a local cachegrind run on the benchmark, the entirety of the regression is from a closure within rustc_metadata::rmeta::decoder::cstore_impl::provide.

I suspect that may be consistent with overhead you get from slight changes in where definitions end up in the encoded metadata from a change like this to libstd.

But also, if you look at the graph, it looks like this is variance that immediately resolved itself in the history of that benchmark:

image

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Apr 20, 2022
@JulianKnodt JulianKnodt deleted the slice_remainder branch April 26, 2022 17:09
@dtolnay dtolnay changed the title Add slice::remainder Add core::slice::Split::as_slice Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.