Skip to content

perf(Algebra/Category/ModuleCat/Presheaf): speed up the monoidal pushforward instance#41753

Open
kbuzzard wants to merge 1 commit into
leanprover-community:masterfrom
kbuzzard:perf-pushforward-zero-monoidal
Open

perf(Algebra/Category/ModuleCat/Presheaf): speed up the monoidal pushforward instance#41753
kbuzzard wants to merge 1 commit into
leanprover-community:masterfrom
kbuzzard:perf-pushforward-zero-monoidal

Conversation

@kbuzzard

@kbuzzard kbuzzard commented Jul 14, 2026

Copy link
Copy Markdown
Member

This was one of the slowest declarations to typecheck in mathlib. Replacing an Iso.refl with something more explicit yields something which the kernel finds far easier to swallow. As a bonus we can remove a set_option backward.isDefEq.respectTransparency false.

…forward instance

The `Functor.Monoidal` instance for `pushforward₀OfCommRingCat` used `Iso.refl _`
for `μIso`. Although that is correct, it forces the unitality and associativity
fields to be proved by tactics that leave a very large definitional unfolding for
the kernel to redo, without the elaborator's caching and lazy unfolding.

Introducing `pushforward₀OfCommRingCatμIso`, which is the same isomorphism but
built section-wise with `isoMk`, lets the coherence fields be discharged by
`tensor_ext`/`tensor_ext₃'` plus `rfl` on sections. The statement of the instance
is unchanged; only the proof term is.

Measured on the file in isolation:

* kernel type checking: 2.27s -> 186ms
* elaboration: 252ms -> 128ms
* whole file (`lake env lean`, incl. ~1.2s of imports): 8.52s -> 3.41s

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip label Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

PR summary 7293186805

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ pushforward₀OfCommRingCatμIso

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

  • +3 new declarations
  • −0 removed declarations
+PresheafOfModules.pushforward₀OfCommRingCatμIso
+PresheafOfModules.pushforward₀OfCommRingCatμIso_hom_app
+PresheafOfModules.pushforward₀OfCommRingCatμIso_inv_app

Decrease in strong tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (strong)
5616 -1 backward.isDefEq.respectTransparency
No changes to weak technical debt.

Current commit 7293186805
Reference commit b86f7b9ebe

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

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Jul 14, 2026
@kbuzzard kbuzzard added the WIP Work in progress label Jul 14, 2026
@kbuzzard

Copy link
Copy Markdown
Member Author

!radar

@leanprover-radar

leanprover-radar commented Jul 14, 2026

Copy link
Copy Markdown

Benchmark results for 7293186 against b86f7b9 are in. There are significant results. @kbuzzard

  • build//instructions: -35.9G (-0.02%)

Large changes (1✅)

  • build/module/Mathlib.Algebra.Category.ModuleCat.Presheaf.PushforwardZeroMonoidal//instructions: -97.3G (-89.47%)

@kbuzzard kbuzzard added LLM-generated PRs with substantial input from LLMs - review accordingly and removed WIP Work in progress labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM-generated PRs with substantial input from LLMs - review accordingly t-algebra Algebra (groups, rings, fields, etc) 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.

2 participants