leanprover-community / leanprover-community/mathlib4

Improving the performance of typeclass inference

Open
#16,644 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

slow-typeclass-synthesis
Dominant language
Lean
Stars
4.2k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

Currently, the performance of typeclass inference in mathlib is still unsatisfactory. This is often because the DFS process enters a node that cannot reach the goal and does a lot of useless searching.

One solution is to adjust the instance priority so that frequent targets are reached more quickly. This can significantly improve performance overall. See previous attempts in #7873 #13852 #13690.

Another solution is to use more mixins to avoid oversized hierarchies, but be careful that this may cause additional searching with the current synthesis algorithm. See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Ways.20to.20speed.20up.20Mathlib/near/468146934.

The following are relevant PRs or experiments.

Adjusting typeclass search paths:

  • (needs to be split) #7873
  • #14712
  • #18464
  • #18468 migrated to mixins
  • #18470
  • #18472
  • #18474

Adding shortcuts:

  • #13852

Slow multi-parameter class instances:

  • #13690
  • #16607
  • #16646
  • #16486
  • #17410
  • #17411
  • #17529
  • #17530
  • #17675

Decouple hierarchies / Migrate to mixin typeclasses:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the prior attempts and experiments linked in the issue, especially the listed pull requests and the Zulip discussion. Identify a bounded typeclass-inference optimization before making changes; done should be demonstrated by improved performance without introducing the cautions described in the issue.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.