Skip to content

[Merged by Bors] - perf: remove some with instance construction patterns#6241

Closed
mattrobball wants to merge 30 commits intomasterfrom
mrb/instance_fields
Closed

[Merged by Bors] - perf: remove some with instance construction patterns#6241
mattrobball wants to merge 30 commits intomasterfrom
mrb/instance_fields

Conversation

@mattrobball
Copy link
Copy Markdown
Contributor

@mattrobball mattrobball commented Jul 29, 2023

The general thought here is that

  { hf.distribMulAction f smul with
    smul := (· • ·)
    ... }

is treated roughly as

  let src := hf.distribMulAction f smul
  { toDistribMulAction :=
    { toMulAction :=
      { smul := (· • ·)
        one_smul := src.one_smul
        mul_smul := src.mul_smul}
      smul_add := src.smul_add 
      smul_zero := src.smul_zero  }
    ... }

which is a much larger term (especially once the let is reduced, due to how many arguments hf.distribMulAction consumes) than

  { toDistribMulAction := hf.distribMulAction f smul
    ... }

In some places the long version is maybe still more desirable, if we want a specific syntactic equality for smul that the base structure defines differently; but none of the examples in this PR are such a case.

Co-authored-by: Eric Wieser wieser.eric@gmail.com


Open in Gitpod

@mattrobball
Copy link
Copy Markdown
Contributor Author

!bench

@mattrobball mattrobball changed the title perf: remove some with instance construction patterns perf: remove some with instance construction patterns Jul 29, 2023
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 42ced2f.Found no runs to compare against.

@eric-wieser
Copy link
Copy Markdown
Member

Before we merge, I'll add an explanation to the PR description of why I think this happens.

@eric-wieser
Copy link
Copy Markdown
Member

eric-wieser commented Jul 31, 2023

bors d+

Please check you agree with the description before merging. I added myself as a co-author since I think the explanation is almost as important as the change here

Though the change really is excellent!

@bors
Copy link
Copy Markdown

bors bot commented Jul 31, 2023

✌️ mattrobball can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@github-actions github-actions bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Jul 31, 2023
@eric-wieser
Copy link
Copy Markdown
Member

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 42ced2f.
There were significant changes against commit 41b6cc2:

  Benchmark                                          Metric                 Change
  ================================================================================
+ build                                              .olean serialization    -6.9%
+ build                                              aesop                  -10.6%
+ build                                              compilation            -16.2%
+ build                                              compilation new        -10.9%
+ build                                              elaboration            -18.1%
+ build                                              import                 -12.3%
+ build                                              initialization         -16.0%
+ build                                              interpretation         -16.3%
+ build                                              linting                -17.8%
+ build                                              parsing                -12.9%
+ build                                              simp                   -17.6%
+ build                                              tactic execution       -21.1%
+ build                                              task-clock             -18.7%
+ build                                              type checking          -17.8%
+ build                                              typeclass inference    -21.4%
+ build                                              wall-clock             -19.6%
+ lint                                               wall-clock             -24.6%
- ~Mathlib.Algebra.Category.ModuleCat.Abelian        instructions             5.7%
- ~Mathlib.Algebra.Category.ModuleCat.Limits         instructions            15.7%
+ ~Mathlib.FieldTheory.Finite.GaloisField            instructions            -5.2%
+ ~Mathlib.FieldTheory.Normal                        instructions            -9.1%
+ ~Mathlib.FieldTheory.PolynomialGaloisGroup         instructions           -10.4%
+ ~Mathlib.FieldTheory.SplittingField.Construction   instructions           -10.9%
+ ~Mathlib.MeasureTheory.Group.AddCircle             instructions            -6.0%
+ ~Mathlib.RingTheory.Polynomial.GaussLemma          instructions           -10.7%

@eric-wieser
Copy link
Copy Markdown
Member

(the previous benchmark apparently might be bogus)

@mattrobball
Copy link
Copy Markdown
Contributor Author

So I guess it caches the runs?

@eric-wieser
Copy link
Copy Markdown
Member

Seems so; I've asked it to discard the last run

@eric-wieser
Copy link
Copy Markdown
Member

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 42ced2f.
There were significant changes against commit 41b6cc2:

  Benchmark                                          Metric                 Change
  ================================================================================
+ build                                              .olean serialization    -6.9%
+ build                                              aesop                  -10.6%
+ build                                              compilation            -16.2%
+ build                                              compilation new        -10.9%
+ build                                              elaboration            -18.1%
+ build                                              import                 -12.3%
+ build                                              initialization         -16.0%
+ build                                              interpretation         -16.3%
+ build                                              linting                -17.8%
+ build                                              parsing                -12.9%
+ build                                              simp                   -17.6%
+ build                                              tactic execution       -21.1%
+ build                                              task-clock             -18.7%
+ build                                              type checking          -17.8%
+ build                                              typeclass inference    -21.4%
+ build                                              wall-clock             -19.6%
+ lint                                               wall-clock             -24.6%
- ~Mathlib.Algebra.Category.ModuleCat.Abelian        instructions             5.7%
- ~Mathlib.Algebra.Category.ModuleCat.Limits         instructions            15.7%
+ ~Mathlib.FieldTheory.Finite.GaloisField            instructions            -5.2%
+ ~Mathlib.FieldTheory.Normal                        instructions            -9.1%
+ ~Mathlib.FieldTheory.PolynomialGaloisGroup         instructions           -10.4%
+ ~Mathlib.FieldTheory.SplittingField.Construction   instructions           -10.9%
+ ~Mathlib.MeasureTheory.Group.AddCircle             instructions            -6.0%
+ ~Mathlib.RingTheory.Polynomial.GaussLemma          instructions           -10.7%

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 42ced2f.
There were significant changes against commit 41b6cc2:

  Benchmark                                          Metric         Change
  ========================================================================
- ~Mathlib.Algebra.Category.ModuleCat.Abelian        instructions     5.7%
- ~Mathlib.Algebra.Category.ModuleCat.Limits         instructions    15.7%
+ ~Mathlib.FieldTheory.Finite.GaloisField            instructions    -5.2%
+ ~Mathlib.FieldTheory.Normal                        instructions    -9.1%
+ ~Mathlib.FieldTheory.PolynomialGaloisGroup         instructions   -10.4%
+ ~Mathlib.FieldTheory.SplittingField.Construction   instructions   -10.9%
+ ~Mathlib.MeasureTheory.Group.AddCircle             instructions    -6.0%
+ ~Mathlib.RingTheory.Polynomial.GaussLemma          instructions   -10.7%

@mattrobball
Copy link
Copy Markdown
Contributor Author

That is what I expect

@eric-wieser
Copy link
Copy Markdown
Member

I think this is probably still worth merging; do you agree?

@mattrobball
Copy link
Copy Markdown
Contributor Author

Do you want to amend?

@mattrobball
Copy link
Copy Markdown
Contributor Author

Oh already done.

@mattrobball
Copy link
Copy Markdown
Contributor Author

bors merge

bors bot pushed a commit that referenced this pull request Aug 2, 2023
The general thought here is that
```lean
  { hf.distribMulAction f smul with
    smul := (· • ·)
    ... }
```
is treated roughly as
```lean
  let src := hf.distribMulAction f smul
  { toDistribMulAction :=
    { toMulAction :=
      { smul := (· • ·)
        one_smul := src.one_smul
        mul_smul := src.mul_smul}
      smul_add := src.smul_add 
      smul_zero := src.smul_zero  }
    ... }
```
which is a much larger term (especially once the `let` is reduced, due to how many arguments `hf.distribMulAction` consumes) than
```lean
  { toDistribMulAction := hf.distribMulAction f smul
    ... }
```

In some places the long version is _maybe_ still more desirable, if we want a specific syntactic equality for `smul` that the base structure defines differently; but none of the examples in this PR are such a case.

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>



Co-authored-by: Matthew Ballard <matt@mrb.email>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@bors
Copy link
Copy Markdown

bors bot commented Aug 2, 2023

Pull request successfully merged into master.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title perf: remove some with instance construction patterns [Merged by Bors] - perf: remove some with instance construction patterns Aug 2, 2023
@bors bors bot closed this Aug 2, 2023
@bors bors bot deleted the mrb/instance_fields branch August 2, 2023 02:18
kim-em pushed a commit that referenced this pull request Aug 2, 2023
The general thought here is that
```lean
  { hf.distribMulAction f smul with
    smul := (· • ·)
    ... }
```
is treated roughly as
```lean
  let src := hf.distribMulAction f smul
  { toDistribMulAction :=
    { toMulAction :=
      { smul := (· • ·)
        one_smul := src.one_smul
        mul_smul := src.mul_smul}
      smul_add := src.smul_add 
      smul_zero := src.smul_zero  }
    ... }
```
which is a much larger term (especially once the `let` is reduced, due to how many arguments `hf.distribMulAction` consumes) than
```lean
  { toDistribMulAction := hf.distribMulAction f smul
    ... }
```

In some places the long version is _maybe_ still more desirable, if we want a specific syntactic equality for `smul` that the base structure defines differently; but none of the examples in this PR are such a case.

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>



Co-authored-by: Matthew Ballard <matt@mrb.email>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
kim-em pushed a commit that referenced this pull request Aug 2, 2023
The general thought here is that
```lean
  { hf.distribMulAction f smul with
    smul := (· • ·)
    ... }
```
is treated roughly as
```lean
  let src := hf.distribMulAction f smul
  { toDistribMulAction :=
    { toMulAction :=
      { smul := (· • ·)
        one_smul := src.one_smul
        mul_smul := src.mul_smul}
      smul_add := src.smul_add 
      smul_zero := src.smul_zero  }
    ... }
```
which is a much larger term (especially once the `let` is reduced, due to how many arguments `hf.distribMulAction` consumes) than
```lean
  { toDistribMulAction := hf.distribMulAction f smul
    ... }
```

In some places the long version is _maybe_ still more desirable, if we want a specific syntactic equality for `smul` that the base structure defines differently; but none of the examples in this PR are such a case.

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>



Co-authored-by: Matthew Ballard <matt@mrb.email>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
kim-em pushed a commit that referenced this pull request Aug 3, 2023
The general thought here is that
```lean
  { hf.distribMulAction f smul with
    smul := (· • ·)
    ... }
```
is treated roughly as
```lean
  let src := hf.distribMulAction f smul
  { toDistribMulAction :=
    { toMulAction :=
      { smul := (· • ·)
        one_smul := src.one_smul
        mul_smul := src.mul_smul}
      smul_add := src.smul_add 
      smul_zero := src.smul_zero  }
    ... }
```
which is a much larger term (especially once the `let` is reduced, due to how many arguments `hf.distribMulAction` consumes) than
```lean
  { toDistribMulAction := hf.distribMulAction f smul
    ... }
```

In some places the long version is _maybe_ still more desirable, if we want a specific syntactic equality for `smul` that the base structure defines differently; but none of the examples in this PR are such a case.

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>



Co-authored-by: Matthew Ballard <matt@mrb.email>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
kim-em pushed a commit that referenced this pull request Aug 14, 2023
The general thought here is that
```lean
  { hf.distribMulAction f smul with
    smul := (· • ·)
    ... }
```
is treated roughly as
```lean
  let src := hf.distribMulAction f smul
  { toDistribMulAction :=
    { toMulAction :=
      { smul := (· • ·)
        one_smul := src.one_smul
        mul_smul := src.mul_smul}
      smul_add := src.smul_add 
      smul_zero := src.smul_zero  }
    ... }
```
which is a much larger term (especially once the `let` is reduced, due to how many arguments `hf.distribMulAction` consumes) than
```lean
  { toDistribMulAction := hf.distribMulAction f smul
    ... }
```

In some places the long version is _maybe_ still more desirable, if we want a specific syntactic equality for `smul` that the base structure defines differently; but none of the examples in this PR are such a case.

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>



Co-authored-by: Matthew Ballard <matt@mrb.email>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants