Repository navigation
Conversation
The `StateRefT'`-based `MonadDStore`/`MonadStore` instances in `Lake.Util.StoreInsts` implement a memo lookup as `modifyGet fun m => (m.get? k, m)`. On a multi-threaded ref, `ST.Ref.modifyGet` takes the cell (an atomic exchange with null) and holds it for the duration of the tree search; `lean_st_ref_take` spins, without backoff, while the cell is taken. Lake's build store (the `StateRefT' IO.RealWorld BuildStore` layer of `RecBuildT`) is such a ref, so every memo lookup of every build thread is serialized through one spinlock, and a holder that is preempted leaves all other threads spinning. The lookups are frequent: `fetchTransImportArts` walks each compiled module's transitive import closure with two store fetches per transitive import, concurrently on every pool thread. On a 192-vCPU machine building a 26k-module workspace with import closures of 700-2,200 modules, `lake` accounted for 38.5k of the build's 99k CPU-seconds; `perf` attributed 97% of lake's cycles to `lean_st_ref_take`, with every sampled stack inside `Lake.recFetch`/`recFetchWithIndex`. A lookup now reads the map with `get` instead: `ST.Ref.get` holds the cell only while it bumps a reference count, and a read of a persistent map needs no exclusion. Only `store` (an insert) still takes the cell. The `StateT` instances are unchanged; `modifyGet` on a pure state involves no ref. Same machine and workspace, clean build: 930 s to 754 s wall, 90.1k to 48.8k user CPU-seconds in total, lake's own CPU time 38.5k to 3.2k CPU-seconds.
Contributor
|
!bench |
|
Benchmark results for 63e1769 against 8258e75 are in. No significant results found. @Rob23oba
Small changes (2🟥)
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
StateRefT'-basedMonadDStore/MonadStoreinstances inLake.Util.StoreInstsimplement a memo lookup asmodifyGet fun m => (m.get? k, m). On a multi-threaded ref,ST.Ref.modifyGettakes the cell (an atomic exchange with null) and holds it for the duration of the tree search;lean_st_ref_takespins, without backoff, while the cell is taken. Lake's build store (theStateRefT' IO.RealWorld BuildStorelayer ofRecBuildT) is such a ref, so every memo lookup of every build thread is serialized through one spinlock, and a holder that is preempted leaves all other threads spinning.The lookups are frequent:
fetchTransImportArtswalks each compiled module's transitive import closure with two store fetches per transitive import, concurrently on every pool thread. On a 192-vCPU machine building a 26k-module workspace with import closures of 700-2,200 modules,lakeaccounted for 38.5k of the build's 99k CPU-seconds;perfattributed 97% of lake's cycles tolean_st_ref_take, with every sampled stack insideLake.recFetch/recFetchWithIndex.A lookup now reads the map with
getinstead:ST.Ref.getholds the cell only while it bumps a reference count, and a read of a persistent map needs no exclusion. Onlystore(an insert) still takes the cell. TheStateTinstances are unchanged;modifyGeton a pure state involves no ref.Same machine and workspace, clean build: 930 s to 754 s wall, 90.1k to 48.8k user CPU-seconds in total, lake's own CPU time 38.5k to 3.2k CPU-seconds.