New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapshots: allow snapshotting some user code #4720
Conversation
This adds some basic ability to snapshot after executing user code. It is pretty brittle right now: 1. It will crash if the user loads any binary extensions before taking the snapshot 2. It doesn't track changes to the file system 3. It doesn't mind there being non-reproducible objects in the hiwire map Snapshots will probably have to be experimental for quite a while. 1. I think I have a pretty good solution for this, which I can work on in a followup. 2. One possibility here is we could serialize the entire filesystem state into the memory snapshot. This would be hard and make the snapshot big, but we wouldn't have to load python_stdlib.zip when restoring from a snapshot so it probably wouldn't increase the total download size by much... 3. Should be pretty easy to fix.
Thanks for the heads up! Regarding point 1, does that mean that only pure python packages can be imported before generating the snapshot? |
Yeah after this PR that is still the case. I will remove this restriction in the next PR. To fix it we have to patch this line in Emscripten: |
Cool! To test it in my application I need to import packages with C extensions. Point 2 is not a problem and I don't understand what point 3 means 😅 Happy to see that you are getting closer to it! |
For number 3, the issue is if you did something like:
Pyodide says okay |
I guess we'll also have a problem if ctypes is used... |
a77703b
to
2c36fff
Compare
2c36fff
to
dcec300
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. To be honest, I don't understand the code inside snapshot.ts
, but it somehow works so I'll approve so you can do further experiments :) I hope we can clean up the code when this feature gets more stable.
This reverts commit aceee6c.
This adds some basic ability to snapshot after executing user code. It is pretty brittle right now:
Snapshots will probably have to be experimental for quite a while. This should ideally get a bunch of tests.
I think I have a pretty good solution for this, which I can work on in a followup.
One possibility here is we could serialize the entire filesystem state into the memory snapshot. This would be hard and make the snapshot big, but we wouldn't have to load python_stdlib.zip when restoring from a snapshot so it probably wouldn't increase the total download size by much...
Should be pretty easy to fix.
cc @pfebrer
Checklists