You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unlike #2471 I do have a reason and two data points that actually back this one up! I measured the most memory allocating functions using valgrind's DHAT tool while running a recent lean nightly on std4's biggest file (Std/Data/List/Lemmas.lean). The DHAT viewer shows that (among other things) this forEachExprWhere call is responsible for a significant chunk of allocations:
The initial count of total allocations was (a second run yielded almost identical numbers):
==3641472== Total: 2,524,478,041 bytes in 964,045 blocks
Judging from the doc-string in the implementation of forEachExprWhere it should only be favored over forEachExpr if the proposition (in this case isFVar) doesn't hold for many subterms. However there are of course a ton of subterms that are free variables here. So I decided to try and switch this to forEachExpr instead which yielded:
==3644111== Total: 1,750,132,393 bytes in 952,715 blocks
on the same file, the allocation chunk also disappeared from my measurements. I furthermore measured std4 compilation time and did get a measurable speedup in:
before:
lake build 369.35s user 14.23s system 446% cpu 1:25.95 total
after:
lake +lean4 build 288.33s user 12.46s system 436% cpu 1:08.92 total
I thus again request someone with privileges to give the bench run a try^^
@Kha, I wonder why linting did not show as a significant change? The change is well above the 10 standard deviations (it's 85.6 stddev) and 1% threshold (it's 12.8%) in the formula.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
awaiting-reviewWaiting for someone to review the PRbuilds-mathlibCI has verified that Mathlib builds against this PR
7 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unlike #2471 I do have a reason and two data points that actually back this one up! I measured the most memory allocating functions using

valgrind'sDHATtool while running a recent lean nightly onstd4's biggest file (Std/Data/List/Lemmas.lean). The DHAT viewer shows that (among other things) thisforEachExprWherecall is responsible for a significant chunk of allocations:The initial count of total allocations was (a second run yielded almost identical numbers):
Judging from the doc-string in the implementation of
forEachExprWhereit should only be favored overforEachExprif the proposition (in this caseisFVar) doesn't hold for many subterms. However there are of course a ton of subterms that are free variables here. So I decided to try and switch this toforEachExprinstead which yielded:on the same file, the allocation chunk also disappeared from my measurements. I furthermore measured std4 compilation time and did get a measurable speedup in:
before:
after:
I thus again request someone with privileges to give the bench run a try^^