Repository navigation
perf: parallel walk and merge, byte-identical output (stacked on #61) - #63
Open
abhiapsunde wants to merge 2 commits into
Open
abhiapsunde wants to merge 2 commits into
abhiapsunde wants to merge 2 commits into
Conversation
`visitedNames`, `visitedLevels` and `visitedExprs` were `Std.HashMap α Nat`s. At 43–53 bytes per distinct object they make up most of the exporter's own memory on large exports. They become `Export.IndexSet α`: the elements stored once in insertion order, in chunks, plus an open-addressing table of 4-byte indices kept at most half full, for 16–24 bytes per object. The numbering and the `BEq`/`Hashable` instances are unchanged, so the output is unchanged byte for byte, except in one case where it was unreadable before (below). Exporting more than `2 ^ 32 - 1` distinct objects of one kind now fails with an error. Exporting a string literal first exports `Char.ofNat` and `String.ofList`. If one of them contains the same literal, which is not the case with `Init` but can be with a custom prelude, the old code gave the literal's index to the next object as well, so the file bound one index twice. `Export.parseStream` overwrites the first binding, but a reader that checks for this, such as the one in Lean core, rejects the file. The literal is now written twice under two indices. A test in `Test.lean` covers this, next to a test of `IndexSet` against `Std.HashMap`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds Export/Par.lean (ExportPar.run). A producer thread follows the sequential control flow and spawns one worker per root expression. Workers record their distinct nodes in first-visit post-order. One merge thread assigns the global indices in the original order, so the output is byte-identical to the sequential exporter. Entries are formatted in batches by tasks and written in order. The first Nat or String literal still triggers the Nat / Char.ofNat / String.ofList exports at the same point as before, including the re-entrant case in Test.lean. Export.lean: output formatting is pipelined (--serial-output turns it off) and M.run flushes queued output before returning. --serial-walk and --export-mdata keep the sequential walk. Tests compare sequential and parallel output on the re-entrant literal prelude and on a set of constants with literals, binders, let and projections. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Stacked on #61: the first commit in this PR is #61's, by alonbase, and is not mine. Only
73d9ad9is new. Rebase onto master once #61 merges. Problem statement and measurements are in #62.Adds
Export/Par.lean(ExportPar.run): producer thread plus one worker per root expression plus one ordered merge thread, so the output matches the sequential exporter byte for byte. Pipelines output formatting (--serial-outputdisables it) and makesM.runflush queued output.--serial-walkand--export-mdatakeep the sequential walk.Results: full Riemann export 27:35 vs 1:53:37 for #61 alone, same sha256 (
5ea74b91…6be244e), peak RSS 88.8 vs 86.9 GB. Memory is not lower than #61, CPU time is higher.lake testpasses with two new sequential-vs-parallel byte comparison tests, including the re-entrant literal case.Not a request to merge before #61. Open question for maintainers: this repository or Lean core's exporter?
🤖 Generated with Claude Code