perf: special case single-child nodes in DiscrTree - #14805
Conversation
38be04a to
bbd620d
Compare
|
!bench |
|
Benchmark results for bbd620d against 5594178 are in. There are significant results. @robsimmons
Medium changes (6✅, 1🟥)
Small changes (240✅, 32🟥)
|
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
|
The adaptation PR for this PR is leanprover/downstream-lean4#23. |
1e5a4d6 to
3048b87
Compare
|
!bench |
|
Benchmark results for 380b07b against 7976735 are in. There are significant results. @robsimmons
Medium changes (4✅, 1🟥)
Small changes (236✅, 34🟥)
|
8c23b20 to
08ea7af
Compare
|
!bench |
|
Benchmark results for 08ea7af against a2d16ea are in. There are significant results. @robsimmons
Medium changes (6✅)
Small changes (336✅, 5🟥)
|
|
Related attempt: #12838 |
|
!bench mathlib |
|
Benchmark results for leanprover-community/mathlib4-nightly-testing@ad7f730 against leanprover-community/mathlib4-nightly-testing@5a95bed are in. There are significant results. @robsimmons
No significant changes detected. |
|
Aah cool @nomeata! This is intentionally trying to be less ambitious, and @Vtec234 convinced me that there were some reasons to be cautious about the I think your separation of leaf nodes (values) from path/branch nodes also really makes sense, but from a "that's a good refactor that makes the data structure operations clearer" sense, I doubt it would be a huge optimization. |
a2d16ea to
020ac29
Compare
ca29358 to
d62a3fd
Compare
020ac29 to
9bd1c68
Compare
d62a3fd to
c6f7c1a
Compare
9bd1c68 to
1be6c1f
Compare
This PR ensures that `DiscrTree` operations collapse any trie nodes that end up empty. This change allows `mapArraysM` to properly implement Aesop's filterDiscrTreeM in the [downstream adaptation PR](leanprover/downstream-lean4#24), which also deprecates `Trie.isEmptyTrie` in favor of the now-upstreamed `Trie.isEmptyNode`. Following Aesop's lead, this PR also adds @[specialize] annotations to the recursive portion of for mapArraysM and to the similarly-patterned foldM and foldValuesM. Three new test files provide coverage of these and other DiscrTree operations. This PR (and the tests) are intended to lay groundwork for leanprover#14805.
73da2fd to
ef67942
Compare
more tests, mapArrays fix and test cases better test coverage for basic discrimination tree options refactor getMatchLoop(s) for .chain Add public interface Trie.mkNode / Trie.asNode for downstream's sake formatting
73da2fd to
4ffd4cf
Compare
This PR creates an additional view abstraction on `DiscrTree.Trie` nodes that allows nodes to be viewed and inspected without direct case analysis. This interface allows downstream code to tolerate future minor changes to DiscrTree representations (e.g. leanprover#12838 or leanprover#14805) more gracefully than is currently possible.
This PR adds a new branch to the
DiscrTreedata structure, giving a lighter-weight way of representing discrimination tree keys with no values and a single node. The value.child k vis treated as equivalent to.node #[] #[(k, v)].Rationale: in many applications, many or most of the nodes in a trie are single-child-no-value-carrying nodes (the robot assistant claimed this was >80% in the case of the Simp post-tree for all of Mathlib, but I wouldn't stand behind that). Special-casing this common case is often an easy win for memory usage and for performance, and this PR is in part a generalization of the match optimization from #11889.
Builds on top of #14844, which modifies the semantics of
DiscrTrie.mapArraysin order to simplify downstream adaptation.Memory usage reduction
The big change not captured in benchmarking is that this PR makes it ~9% less expensive, in terms of unshared memory usage, for a file worker to
import Lean, and about ~20% less expensive for a file worker toimport Mathlib. To easily see the ~9% improvement on a linux/x86 system, you can create a lean file Mem.leanand then run these commands:
(you may need to rerun it a few times until the Pss_Anon and Private_Dirty are close to each other, the number isn't stable right when the toolchain downloads for reasons I don't fully understand)
Full Glossy Claude Writeup if that interests you.