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

Speed up Vec::clear(). #96002

Merged
merged 1 commit into from
Apr 17, 2022
Merged

Commits on Apr 13, 2022

  1. Speed up Vec::clear().

    Currently it just calls `truncate(0)`. `truncate()` is (a) not marked as
    `#[inline]`, and (b) more general than needed for `clear()`.
    
    This commit changes `clear()` to do the work itself. This modest change
    was first proposed in rust-lang#74172, where the reviewer rejected it because
    there was insufficient evidence that `Vec::clear()`'s performance
    mattered enough to justify the change. Recent changes within rustc have
    made `Vec::clear()` hot within `macro_parser.rs`, so the change is now
    clearly worthwhile.
    
    Although it doesn't show wins on CI perf runs, this seems to be because they
    use PGO. But not all platforms currently use PGO. Also, local builds don't use
    PGO, and `truncate` sometimes shows up in an over-represented fashion in local
    profiles. So local profiling will be made easier by this change.
    
    Note that this will also benefit `String::clear()`, because it just
    calls `Vec::clear()`.
    
    Finally, the commit removes the `vec-clear.rs` codegen test. It was
    added in rust-lang#52908. From before then until now, `Vec::clear()` just called
    `Vec::truncate()` with a zero length. The body of Vec::truncate() has
    changed a lot since then. Now that `Vec::clear()` is doing actual work
    itself, and not just calling `Vec::truncate()`, it's not surprising that
    its generated code includes a load and an icmp. I think it's reasonable
    to remove this test.
    nnethercote committed Apr 13, 2022
    Configuration menu
    Copy the full SHA
    9c59d04 View commit details
    Browse the repository at this point in the history