Skip to content

Bad trait solving performance with bounds on associated types #6432

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
flodiebold opened this issue Nov 1, 2020 · 1 comment
Open

Bad trait solving performance with bounds on associated types #6432

flodiebold opened this issue Nov 1, 2020 · 1 comment
Labels
A-perf performance issues A-ty type system / type inference / traits / method resolution S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@flodiebold
Copy link
Member

A bound like T::Item: Debug can slow down trait solving a lot because it will currently result in a search through all Debug impls (this case will be hit), see e.g. #6362.
rust-lang/chalk#589 should solve this, but the changes in rust-lang/chalk#638 should probably also fix it in most cases. At some point, I'd like to remove the above-mentioned unrestricted search case (i.e. return an empty list instead), which would make sure we don't get bad performance at the cost of getting wrong results if we encounter that situation (which we shouldn't).

@flodiebold flodiebold added the A-ty type system / type inference / traits / method resolution label Nov 1, 2020
@flodiebold flodiebold added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Dec 21, 2020
@Veykril Veykril added the A-perf performance issues label Jan 17, 2022
@davidbarsky
Copy link
Contributor

I've resurrected syntactic equality in this branch. Those changes, unfortunately, regressed analysis-stats:

With the revived syntactic equality
~/.cargo/bin/rust-analyzer analysis-stats .
Database loaded:     6.79s, 0b (metadata 583.04ms, 0b; build 467.74ms, 0b)
  item trees: 1312
Item Tree Collection: 870.91ms, 0b
  crates: 66, mods: 1138, decls: 30847, bodies: 27986, adts: 2266, consts: 1535
Item Collection:     9.53s, 0b
Body lowering:       7.21s, 0b                                                                            exprs: 811009, ??ty: 332 (0%), ?ty: 737 (0%), !ty: 345                                                                                        pats: 184005, ??ty: 95 (0%), ?ty: 144 (0%), !ty: 6
Inference:           129.46s, 0b
MIR lowering:        21.29s, 0b
Mir failed bodies: 404 (1%)
Data layouts:        81.79ms, 0b
Failed data layouts: 132 (6%)
Const evaluation:    217.89ms, 0b
Failed const evals: 1 (0%)
Total:               168.67s, 0b
On the master branch
~/.cargo/bin/rust-analyzer analysis-stats .
Database loaded:     1.48s, 0b (metadata 535.90ms, 0b; build 315.57ms, 0b)
  item trees: 1235
Item Tree Collection: 830.16ms, 0b
  crates: 62, mods: 1059, decls: 28552, bodies: 25901, adts: 2059, consts: 1345
Item Collection:     9.31s, 0b
Body lowering:       6.23s, 0b                                                                            exprs: 747434, ??ty: 40 (0%), ?ty: 136 (0%), !ty: 3                                                                                           pats: 169587, ??ty: 4 (0%), ?ty: 4 (0%), !ty: 0
Inference:           36.95s, 0b
MIR lowering:        6.88s, 0b
Mir failed bodies: 19 (0%)
Data layouts:        73.04ms, 0b
Failed data layouts: 132 (6%)
Const evaluation:    409.49ms, 0b
Failed const evals: 1 (0%)
Total:               60.70s, 0b

(note that when I comment out the unbounded search section, inference drops to 130ms.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-perf performance issues A-ty type system / type inference / traits / method resolution S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

3 participants