Skip to content

[Merged by Bors] - perf: lower priority of sheafToPresheaf_isRightAdjoint - #41462

Closed
felixpernegger wants to merge 5 commits into
leanprover-community:masterfrom
felixpernegger:lowerprio
Closed

felixpernegger wants to merge 5 commits into
leanprover-community:masterfrom
felixpernegger:lowerprio

Conversation

@felixpernegger

@felixpernegger felixpernegger commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

This was found in the course of #41222 (where this is needed to avoid big increases) by Fable 5, but should already be beneficial now.


Open in Gitpod

@felixpernegger

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Jul 7, 2026 •

Copy link
Copy Markdown

Benchmark results for 306d73b against d8d7c66 are in. There are significant results. @felixpernegger

  • ✅ build//instructions: -39.7G (-0.03%)

Large changes (3✅)

  • ✅ build/module/Mathlib.Condensed.Discrete.Characterization//instructions: -22.7G (-51.27%)
  • ✅ build/module/Mathlib.Condensed.Discrete.Module//instructions: -12.3G (-30.59%)
  • ✅ build/module/Mathlib.Condensed.Light.Monoidal//instructions: -15.1G (-66.75%)

Medium changes (2✅)

  • ✅ build/module/Mathlib.CategoryTheory.Sites.SheafCohomology.Basic//instructions: -9.5G (-16.43%)
  • ✅ build/module/Mathlib.Condensed.Light.Module//instructions: -4.8G (-43.14%)

Small changes (4✅)

  • ✅ build/module/Mathlib.CategoryTheory.Sites.MayerVietorisSquare//instructions: -2.2G (-12.08%)
  • ✅ build/module/Mathlib.Condensed.Light.AB//instructions: -2.5G (-29.91%)
  • ✅ build/module/Mathlib.Condensed.Light.Epi//instructions: -2.5G (-13.88%)
  • ✅ build/module/Mathlib.Condensed.Light.Small//instructions: -1.3G (-11.37%)

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

PR summary 39a7059f7c

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ instance (priority := 900) sheafToPresheaf_isRightAdjoint : (sheafToPresheaf J D).IsRightAdjoint
- sheafToPresheaf_isRightAdjoint

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 39a7059).

  • +0 new declarations
  • −0 removed declarations

No declaration differences.


No changes to strong technical debt.

No changes to weak technical debt.

Current commit 39a7059f7c
Reference commit 7c7bc0bdd5

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

Comment thread Mathlib/Condensed/Discrete/Module.lean Resolved
mathlib-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…icitly (#41483)

This is beneficial for the same reasons as #40964. This particular change matters for #41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
@kbuzzard

kbuzzard commented Jul 8, 2026

Copy link
Copy Markdown
Member

The one remaining change in this PR (when master is merged) is going to be this reduced priority hack having a surprising effect on compile time. My instinct is that before this is merged we should at least have some understanding as to what is going on and why. For example if it's the same phenomenon as #lean4 > abbrev causes unfolding @ 💬 then the actual fix might be something else (a shortcut instance, for example).

@grunweg grunweg added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Jul 8, 2026
michaellee94 pushed a commit to michaellee94/mathlib4 that referenced this pull request Jul 11, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
mpacholski pushed a commit to mpacholski/mathlib4 that referenced this pull request Jul 16, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
mpacholski pushed a commit to mpacholski/mathlib4 that referenced this pull request Jul 30, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
mpacholski pushed a commit to mpacholski/mathlib4 that referenced this pull request Jul 30, 2026
…icitly (leanprover-community#41483)

This is beneficial for the same reasons as leanprover-community#40964. This particular change matters for leanprover-community#41462; extracted from that PR.

Co-authored-by: felixpernegger <[email protected]>
@felixpernegger

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Aug 19, 2026 •

Copy link
Copy Markdown

Benchmark results for 80b8554 against 1fe0a51 are in. There are significant results. @felixpernegger

  • ✅ build//instructions: -43.1G (-0.03%)

Large changes (3✅)

  • ✅ build/module/Mathlib.CategoryTheory.Sites.SheafCohomology.Basic//instructions: -7.7G (-19.52%)
  • ✅ build/module/Mathlib.Condensed.Discrete.Characterization//instructions: -14.5G (-43.31%)
  • ✅ build/module/Mathlib.Condensed.Light.Monoidal//instructions: -9.8G (-57.54%)

Medium changes (3✅)

  • ✅ build/module/Mathlib.Condensed.Discrete.Module//instructions: -7.7G (-24.17%)
  • ✅ build/module/Mathlib.Condensed.Light.AB//instructions: -1.6G (-22.55%)
  • ✅ build/module/Mathlib.Condensed.Light.Module//instructions: -3.2G (-33.75%)

Small changes (3✅)

  • ✅ build/module/Mathlib.CategoryTheory.Sites.MayerVietorisSquare//instructions: -1.4G (-8.91%)
  • ✅ build/module/Mathlib.Condensed.Light.Epi//instructions: -1.7G (-10.92%)
  • ✅ build/module/Mathlib.Condensed.Light.Small//instructions: -1.2G (-11.06%)

@felixpernegger

Copy link
Copy Markdown
Contributor Author

It looks like the slowdown is coming from instHasWeakSheafifyOfHasSheafify:

When try to synthesise (sheafToPresheaf J A).IsRightAdjoint /HasWeakSheafify J A, the instance whose priority I lowered is first tried (since it comes later); however it has quite a lot of assumptions (see here), which cause the slowdown.

For the competing instHasWeakSheafifyOfHasSheafify, HasSheafify on the other hand has useful instances, which make the synthesis fast.

So probably making instance shortcuts for Modules and the Light- things affected here, would also work, but as the given instance is so complicated already; simply lowering its priority (and thus trying it later), seems the better choice to me. (Unless maybe down the line this instance as a mathematical statement is really central, however this doesnt seem the case now. But since I dont understand the math here I cant comment on that)

(I used GPT 5.6 Sol for parts of this investigation for what its worth)

@felixpernegger

Copy link
Copy Markdown
Contributor Author

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Aug 19, 2026
@joelriou

Copy link
Copy Markdown
Contributor

Thanks!

bors merge

@mathlib-bors mathlib-bors Bot added the ready-to-merge This PR has been sent to bors. label Sep 21, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
This was found in the course of #41222 (where this is needed to avoid big increases) by Fable 5, but should already be beneficial now.

Co-authored-by: Batixx <[email protected]>
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 21, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

@mathlib-bors mathlib-bors Bot changed the title perf: lower priority of sheafToPresheaf_isRightAdjoint [Merged by Bors] - perf: lower priority of sheafToPresheaf_isRightAdjoint Sep 21, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 21, 2026
grunweg pushed a commit to grunweg/mathlib4 that referenced this pull request Sep 22, 2026
…community#41462)

This was found in the course of leanprover-community#41222 (where this is needed to avoid big increases) by Fable 5, but should already be beneficial now.

Co-authored-by: Batixx <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants