Skip to content

Bad trait solving performance with bounds on associated types #6432

Closed

Description

@flodiebold

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

Activity

  1. added
    A-ty
    on Nov 1, 2020
  2. added
    S-unactionable
    on Dec 21, 2020
  3. added
    A-perf
    on Jan 17, 2022
  4. davidbarsky commented on Feb 9, 2024

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

  5. ChayimFriedman2 commented on Jan 12, 2026

    @ChayimFriedman2
    Contributor

    Made irrelevant by the switch to the new solver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-perfA-tyS-unactionable

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions