Repository navigation
perf: do not log picks during the model checker's search - #97
Merged
Merged
Conversation
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.
Problem. Extracted actions keep a log with every result: each pick records the candidate it chose, formatted with
Repr. The model checker's search and#simulatenever read it (trdrops the log as soon as an action returns), yet they paid for it on every state.This PR puts the log behind a runtime switch,
LogSwitch. The search and#simulaterun with it off. Recovering a counterexample trace runs a second copy of the transition system with it on (findReachableThentakes a lazily builttraceSysforrecoverTrace), so the log stays available where it may be read.Implementation details.
LogSwitchis@[nospecialize]: the switch is a runtime argument, and every action is still compiled once. The log is invisible towp, so the switched log instance is lawful and extraction stays certified; Veil's wrapper rules (pickSuchThat_VeilM,assume_VeilM,require_VeilM,pickSuchThat_bind_VeilM) are now generic in the log instance, like Loom's.Why it saves both time and memory. With the log on, every candidate that has results costs a
Reprcall that allocates aStd.Formattree (a large one when the candidate is a message or a set), plus a fresh log and result pair for each result the entry is prepended to, all of it dropped right after the action returns. With the log off, the log is[]: the compiler moves theReprcall into the branch that logs, and thebindafter the pick takes Loom's empty-log fast path, returning the continuation's results untouched. The work and the allocations are gone, and so is the memory the entries took: results that are alive at the same time, notably the initial states, which are built as one list, no longer carry formatted copies of the values picked for them. Specs without picks are unaffected; the gain grows with the cost of formatting the picked values.Tested by
VeilTest/Regression/PickLogSwitch.lean: with the switch off every log is empty, with it on the logs list the picked candidates in order, and the results are the same.