Skip to content

Conversation

@Zsailer
Copy link
Collaborator

@Zsailer Zsailer commented Jul 22, 2025

Summary

This PR optimizes cell execution state tracking by moving execution states from YDoc transactions to the document awareness layer, significantly reducing memory usage and improving performance in collaborative Jupyter notebooks.

Key Changes

Architectural Improvements

  • Move execution states to awareness layer: Cell execution states ("busy", "idle") now live in ephemeral awareness instead of persistent YDoc
  • Reduce YDoc transaction volume: Separate persistent document state from ephemeral collaboration state
  • Improve memory efficiency: Eliminate execution state accumulation in YDoc transaction history
  • Enhance scalability: Better performance for notebooks with heavy cell execution patterns

Performance Optimizations

  • Dramatically reduced YDoc transactions during cell execution cycles
  • Lower memory footprint for long-running notebook sessions
  • Faster document synchronization without execution state noise
  • Better collaborative experience with real-time state updates

Technical Implementation

  • Store execution states in YRoom._cell_execution_states (in-memory)
  • Broadcast states via awareness for real-time collaboration
  • Maintain state persistence across client reconnections
  • Preserve execution counts and outputs in YDoc for true persistence

Copy link
Collaborator

@3coins 3coins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zsailer
This is a great improvement, thanks for working on these changes. Left some minor feedback.

@Zsailer
Copy link
Collaborator Author

Zsailer commented Jul 23, 2025

Thanks for the feedback @3coins! I've addressed all your suggestions:

  1. Simplified conditional logic: Combined the three else blocks in _updatePrompt method into a single else block since they all had the same behavior
  2. Improved null checking: Used optional chaining (notebook?.model?.sharedModel?.awareness) to simplify the null checking in _getCellExecutionStateFromAwareness
  3. Added YRoom helper method: Created set_cell_awareness_state() method in YRoom class for better encapsulation and updated the kernel client to use this new method

The changes improve code readability and maintainability while keeping the same functionality. All updates have been pushed to the branch.

@Zsailer Zsailer force-pushed the cell-awareness branch 2 times, most recently from aa7eff6 to 9a08d76 Compare July 23, 2025 04:08
…method

- Combine three similar else blocks in _updatePrompt method into one
- Use optional chaining to simplify null checking in _getCellExecutionStateFromAwareness
- Add set_cell_awareness_state method to YRoom for better encapsulation
- Update kernel client to use new YRoom method for setting cell states
Copy link
Collaborator

@3coins 3coins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Zsailer Zsailer merged commit 71b2e31 into jupyter-ai-contrib:main Jul 23, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants