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

Optimize seen Predicate filtering. #50932

Merged
merged 1 commit into from May 22, 2018
Merged

Conversation

@nnethercote
Copy link
Contributor

@nnethercote nnethercote commented May 21, 2018

This speeds up a few rustc-perf benchmark runs, most notably ones
involving 'coercions', the best by 2%.

This speeds up a few rustc-perf benchmark runs, most notably ones
involving 'coercions', the best by 2%.
@rust-highfive
Copy link
Collaborator

@rust-highfive rust-highfive commented May 21, 2018

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

//
// This code is hot enough that it's worth avoiding the allocation
// required for the FxHashSet when possible. Special-casing lengths 0,
// 1 and 2 covers roughly 75--80% of the cases.

This comment has been minimized.

@eddyb

eddyb May 21, 2018
Member

What about using sort + dedup? That would avoid the allocation, and also quickly exit on small numbers of elements.

This comment has been minimized.

@ishitatsuyuki

ishitatsuyuki May 21, 2018
Contributor

That changes the order, which may break the behavior.

Also, deriving Ord is a pain.

This comment has been minimized.

@nnethercote

nnethercote May 21, 2018
Author Contributor

And Predicate is a large type, so moving the values around might be moderately expensive.

This comment has been minimized.

@eddyb

eddyb May 22, 2018
Member

Oh, I see, the set is used with retain. But you need to clone & move the values into a set anyway. If you want to avoid the cost of data movement, the set could be created using references into the original Vec instead. Except that doesn't work because of the retain...

@eddyb
Copy link
Member

@eddyb eddyb commented May 22, 2018

@bors r+

@bors
Copy link
Contributor

@bors bors commented May 22, 2018

📌 Commit 2ff6324 has been approved by eddyb

@eddyb
Copy link
Member

@eddyb eddyb commented May 22, 2018

kennytm added a commit to kennytm/rust that referenced this pull request May 22, 2018
Optimize seen Predicate filtering.

This speeds up a few rustc-perf benchmark runs, most notably ones
involving 'coercions', the best by 2%.
bors added a commit that referenced this pull request May 22, 2018
Rollup of 15 pull requests

Successful merges:

 - #50846 (Add E0665)
 - #50849 (CheckLoopVisitor: also visit closure arguments)
 - #50863 (Make `[T]::len` and `str::len` const fn)
 - #50875 (rustdoc: use "short form" doc(cfg) printing even when combined with other conditionals)
 - #50913 (Fix typo in cell.rs)
 - #50914 (Issue #50636: Improve error diagnostic with missing commas after struct fields.)
 - #50931 (Inline `try_get`.)
 - #50932 (Optimize seen Predicate filtering.)
 - #50945 (Stabilize feature from_ref)
 - #50946 (rustc: Fix procedural macros generating lifetime tokens)
 - #50947 (rustdoc: set tab width in rust source blocks)
 - #50952 (Add the 2018 edition of the book to doc.rust-lang.org)
 - #50958 (Micro-optimization on PR#50697)
 - #50961 (Fix FileCheck finding with MSVC)
 - #50963 (Right-size the `VecDeque` in `coerce_unsized`.)

Failed merges:
@bors bors merged commit 2ff6324 into rust-lang:master May 22, 2018
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@nnethercote nnethercote deleted the nnethercote:seen-Predicates branch May 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.