Zulip Chat Archive
Stream: general
Topic: REPL garbage collection or fast pickleload
Jiaming Shan (Jun 20 2025 at 15:00):
Ok, so here is the question:
I am using LeanInteract (which is a REPL wrapper). I'm using ProofStep to search possible solution of a given sorry. However, it seems that ProofStep cannot do garbage collection (I mean after I try some possible solution and find I try too much and take too much memory, I want to remove some previously tried ProofStep, but I cannot find this feature) [method 1] [issues: clear memory, gc, LeanInteract)]. Another method is to restart the REPL instance and pickle load the sorry state, but it seems that pickle load need to reload Mathlib because of it's design, so the unpickle is slow (3s, which I expect 0.01s) [method 2] [issues: fast pickle, fork sorry state]. The implementation of AutoLeanServer add_to_session_cache in LeanInteract also relies on pickling, so it doesn't solve the issue.
What's the best way to do this?
Auguste Poiroux (Jun 23 2025 at 14:00):
Hi @Jiaming Shan!
If you are interested in the garbage collection feature, you can try out @RexWang PR. Since you are using LeanInteract, with >=0.6.0, you can:
- Switch the REPL backend to his fork:
config = LeanREPLConfig(
project=TempRequireProject("mathlib"),
repl_git="https://github.com/Lean-zh/repl",
repl_rev="gc-option",
)
- Use
run_dictmethod instead of therunmethod to use the newly introducedrecordparameter:
server.run_dict({"tactic": "linarith", "proofState": 0, "record": False})
Full example
Jiaming Shan (Jun 23 2025 at 14:53):
Thank you! It's good, however my need is to remove previous ProofState, so something like "remove state" is more preferred. This idea is already mentioned in that issue, but I think it is not implemented right?
Auguste Poiroux (Jun 23 2025 at 15:02):
Oh, I see, sorry for the misunderstanding. Indeed, it would be an interesting feature to add. Regarding the behavior of the "delete proofstate" command, since we have a proof state tree, there is the question of the default behavior.
For example, let's say we have proof states 0 and 1, with 1 instantiated from 0. If we wish to delete 0, would you expect it to delete the whole associated subtree (i.e. 0 and 1 here)? or just 0?
I guess deleting only the specific proof state would be the default since proof states are independent once created.
Jiaming Shan (Jun 23 2025 at 15:04):
As you said, I would like to only delete 0 and keep 1 in the memory.
Auguste Poiroux (Jun 23 2025 at 15:15):
I guess it should be doable by replacing this line: proofStates : Array ProofSnapshot := #[] to proofStates : Array (Option ProofSnapshot) := #[], adding a new "remove" command which basically replaces the proof snapshot by None, and updating all the methods to handle this option change gracefully.
I don't have the bandwidth to implement that at the moment though, but maybe you can try to do it?
Jiaming Shan (Jun 23 2025 at 15:16):
Oh I see, that is useful! Thanks!
Jiaming Shan (Jun 29 2025 at 22:38):
So I do it myself and made a PR https://github.com/leanprover-community/repl/pull/111
Auguste Poiroux (Jun 30 2025 at 07:44):
Nice! Did you run tests to check if it is indeed releasing the memory associated to the removed proof states?
Jiaming Shan (Jul 03 2025 at 16:52):
I connect repl with state removing with LeanInteract, and test on LeanInteract to see the memory usage. It works! Although the memory that has been applied for will not be released, but if I release some proof states while continuously increasing the proof state, the program will not apply for new memory, thereby effectively curbing the growth of total memory.
Last updated: Dec 20 2025 at 21:32 UTC