Skip to content

Conversation

@dmadisetti
Copy link
Collaborator

📝 Summary

run mode (which shares the kernel process), does not need the overhead of shared_memory in our virtual file implementation. This abstracts the storage of virtual files, away to just use a dictionary in these simpler cases.

@vercel
Copy link

vercel bot commented Dec 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
marimo-docs Ready Ready Preview, Comment Dec 30, 2025 5:50pm

def read_virtual_file(filename: str, byte_length: int) -> bytes:
if not shared_memory:
if is_pyodide():
Copy link
Contributor

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?

Copy link
Contributor

Copilot AI left a 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 VirtualFileStorage protocol with two implementations: InMemoryStorage (for run mode) and SharedMemoryStorage (for edit mode)
  • Refactored VirtualFileRegistry to 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>
@mscolnick mscolnick merged commit 797c779 into main Dec 30, 2025
37 of 77 checks passed
@mscolnick mscolnick deleted the dm/remove-shared-mem branch December 30, 2025 19:19
@dmadisetti dmadisetti added the bug Something isn't working label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

3 participants