rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Bad trait solving performance with bounds on associated types

Open flodiebold opened this issue 5 years ago • 1 comments

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. https://github.com/rust-lang/chalk/pull/589 should solve this, but the changes in https://github.com/rust-lang/chalk/pull/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 avatar Nov 01 '20 11:11 flodiebold

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.)

davidbarsky avatar Feb 09 '24 00:02 davidbarsky