Skip to content

chore: remove CoeFun instances where FunLike is available#17921

Closed
Vierkantor wants to merge 2 commits intomasterfrom
remove-coefun-test-4
Closed

chore: remove CoeFun instances where FunLike is available#17921
Vierkantor wants to merge 2 commits intomasterfrom
remove-coefun-test-4

Conversation

@Vierkantor
Copy link
Copy Markdown
Contributor

During the port we found that FunLike is robust enough not to need an extra CoeFun shortcut. Let's see if that rule can be consistently applied to the whole of the library.

There is still duplication between FunLike and CoeFun for Grp, Mon, CommGrp and CommMon, which will need a more thorough fix. See also #17866.

I am currently bisecting #17870 to figure out exactly why the benchmarks are indicating a slowdown with no obvious cause.


Open in Gitpod

@Vierkantor Vierkantor added tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip awaiting-bench This PR needs to be benchmarked before merging labels Oct 18, 2024
@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 18, 2024

PR summary acdbe3f73a

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

- instCoeFun
- instance : CoeFun (Π₀ i, β i) fun _ => ∀ i, β i
- instance {μ : YoungDiagram} : CoeFun (SemistandardYoungTableau μ) fun _ ↦ ℕ → ℕ → ℕ

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Oct 18, 2024
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 7254b21.
There were significant changes against commit 672f75b:

  Benchmark                                     Metric         Change
  ===================================================================
- ~Mathlib.Analysis.InnerProductSpace.Adjoint   instructions     8.5%

@Vierkantor Vierkantor force-pushed the remove-coefun-test-4 branch 2 times, most recently from a142021 to 7339c6f Compare October 21, 2024 09:03
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Oct 21, 2024
@mathlib4-dependent-issues-bot
Copy link
Copy Markdown
Collaborator

This PR/issue depends on:

@Vierkantor Vierkantor force-pushed the remove-coefun-test-4 branch from 7339c6f to 8aa42b2 Compare October 21, 2024 11:11
@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 8aa42b2.
There were significant changes against commit ff1b886:

  Benchmark                                     Metric         Change
  ===================================================================
- ~Mathlib.Analysis.InnerProductSpace.Adjoint   instructions     8.3%

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Huh! My suspicion was on Finsupp or DFinsupp but it turns out they are not the problem.

During the port we found that `FunLike` is robust enough not to need an extra `CoeFun` shortcut. Let's see if that rule can be consistently applied to the whole of the library.

There is still duplication between `FunLike` and `CoeFun` for `Grp`, `Mon`, `CommGrp` and `CommMon`, which will need a more thorough fix. See also #17866.

Compared to previous tests, this only preserves the `Finsupp` and `DFinsupp` instances; my guess is that they are the important shortcut instances preventing slowdowns.
@Vierkantor Vierkantor force-pushed the remove-coefun-test-4 branch from 8aa42b2 to acdbe3f Compare October 21, 2024 11:52
@Vierkantor
Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit acdbe3f.
There were no significant changes against commit ff1b886.

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Okay then! Looks like we got the culprit:

instance instCoeFun : CoeFun (E ≃ₛₗᵢ[σ₁₂] E₂) fun _ ↦ E → E₂ := ⟨DFunLike.coe⟩

Not sure why this is particularly slow to apply... But that's to figure out for later.

I'll get the main PR ready to merge.

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

Labels

awaiting-bench This PR needs to be benchmarked before merging tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants