-
Notifications
You must be signed in to change notification settings - Fork 892
fix: do not use shared memory in run case #7637
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
||
| def read_virtual_file(filename: str, byte_length: int) -> bytes: | ||
| if not shared_memory: | ||
| if is_pyodide(): |
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.
can this be removed / handled in the Storage logic?
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.
Pull request overview
This PR optimizes virtual file storage by introducing a storage abstraction layer. Instead of always using shared memory (which has overhead), the code now uses a simple in-memory dictionary for "run" mode where the kernel and server share the same process, while reserving shared memory for "edit" mode where processes are separate.
Key changes:
- Introduced
VirtualFileStorageprotocol with two implementations:InMemoryStorage(for run mode) andSharedMemoryStorage(for edit mode) - Refactored
VirtualFileRegistryto use pluggable storage backends - Updated kernel and script context initialization to select appropriate storage based on session mode
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| marimo/_runtime/virtual_file/storage.py | New file defining storage abstraction with Protocol, SharedMemoryStorage (refactored from virtual_file.py), InMemoryStorage, and VirtualFileStorageManager singleton |
| marimo/_runtime/virtual_file/virtual_file.py | Refactored to use storage abstraction; removed direct shared_memory usage and platform checks |
| marimo/_runtime/virtual_file/init.py | Added module-level exports for new storage classes |
| marimo/_runtime/context/kernel_context.py | Updated to select storage backend (SharedMemoryStorage for EDIT mode, InMemoryStorage for RUN mode) |
| marimo/_runtime/context/script_context.py | Updated to use InMemoryStorage for script execution |
| tests/_runtime/test_storage.py | Comprehensive test suite for both storage implementations and VirtualFileStorageManager |
| marimo/_utils/print.py | Added copyright header |
| marimo/_server/config.py | Added copyright header |
| marimo/_convert/script.py | Added copyright header |
| marimo/_convert/markdown/init.py | Added copyright header |
| marimo/_smoke_tests/pdf.py | Updated version and markdown formatting |
Comments suppressed due to low confidence (1)
marimo/_runtime/virtual_file/virtual_file.py:177
- The VirtualFileRegistry now requires a storage parameter but this is not documented in the class docstring. The class docstring should be updated to explain the storage parameter and the different storage backends available.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
📝 Summary
runmode (which shares the kernel process), does not need the overhead ofshared_memoryin our virtual file implementation. This abstracts the storage of virtual files, away to just use a dictionary in these simpler cases.