Module runtime

Source
Expand description

§Tessera Runtime System

This module provides the global runtime state management for the Tessera UI framework. The runtime system maintains essential application state including the component tree, window properties, and user interface state that needs to be shared across the entire application lifecycle.

§Overview

The TesseraRuntime serves as the central hub for all runtime data and side effects in a Tessera application. It uses a thread-safe singleton pattern to ensure consistent access to shared state from any part of the application, including from multiple threads during parallel component processing.

§Thread Safety

The runtime is designed with parallelization in mind. It uses [parking_lot::RwLock] for efficient read-write synchronization, allowing multiple concurrent readers while ensuring exclusive access for writers. This design supports Tessera’s parallel component tree processing capabilities.

§Usage

Access the runtime through the static methods:

use tessera_ui::TesseraRuntime;

// Read-only access (multiple threads can read simultaneously)
{
    let runtime = TesseraRuntime::read();
    let window_size = runtime.window_size;
    println!("Window size: {}x{}", window_size[0], window_size[1]);
} // Lock is automatically released

// Write access (exclusive access required)
{
    let mut runtime = TesseraRuntime::write();
    runtime.window_size = [1920, 1080];
    runtime.cursor_icon_request = Some(winit::window::CursorIcon::Pointer);
} // Lock is automatically released

§Performance Considerations

  • Prefer read locks when only accessing data
  • Keep lock scopes as narrow as possible to minimize contention
  • The runtime is optimized for frequent reads and occasional writes
  • Component tree operations may involve parallel processing under read locks

Structs§

TesseraRuntime
Central runtime state container for the Tessera UI framework.