Skip to content

Cache more type class queries - #2152

Merged
gebner merged 2 commits into
masterfrom
dontresettccache
Mar 16, 2023
Merged

gebner merged 2 commits into
masterfrom
dontresettccache

Conversation

@gebner

@gebner gebner commented Mar 14, 2023 •

Copy link
Copy Markdown
Member

This PR makes two changes to the TC synthesis cache:

  1. Instead of resetting the cache when adding local instances, we add the list of local instances to the cache key.
  2. We also cache results when they contain metavariables.

Both of these changes address issues in #2055. There we have lots of nested TC problems that are not cached at all. Like a lot of code in mathlib, the universes of the types have level metavariables. But even using Type instead of Type _ doesn't help, because mvarId.withContext (used in the term elaborator when resuming) resets the instance cache when the local instances change. (Presumably because we run the top-level TermElabM in the empty local context, but I haven't investigated this too deeply.)

The two changes combined result in a 10% speedup on mathlib.

@gebner gebner changed the title perf: do not reset tc cache when adding local insts perf: do not reset tc cache when adding local instances Mar 14, 2023
@gebner

gebner commented Mar 14, 2023

Copy link
Copy Markdown
Member Author

!bench

@gebner
gebner force-pushed the dontresettccache branch from 3ae83f6 to d0de71e Compare March 14, 2023 19:32
@leanprover-bot

Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 3ae83f6.
There were no significant changes against commit 96aa021.

@gebner gebner changed the title perf: do not reset tc cache when adding local instances Cache more type class queries Mar 14, 2023
@gebner
gebner marked this pull request as ready for review March 15, 2023 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants