feat: add partial update support with caller-declared dirty tracking

- Add PartialUpdate dataclass and supports_partial_updates to EffectPlugin
- Add dirty region tracking to Canvas (mark_dirty, get_dirty_rows, etc.)
- Canvas auto-marks dirty on put_region, put_text, fill
- CanvasStage exposes dirty rows via pipeline context
- EffectChain creates PartialUpdate and calls process_partial() for optimized effects
- HudEffect implements process_partial() to skip processing when rows 0-2 not dirty
- This enables effects to skip work when canvas regions haven't changed
This commit is contained in:
2026-03-16 16:56:45 -07:00
parent f638fb7597
commit 3a3d0c0607
5 changed files with 132 additions and 3 deletions

View File

@@ -23,6 +23,25 @@ from dataclasses import dataclass, field
from typing import Any
@dataclass
class PartialUpdate:
"""Represents a partial buffer update for optimized rendering.
Instead of processing the full buffer every frame, effects that support
partial updates can process only changed regions.
Attributes:
rows: Row indices that changed (None = all rows)
cols: Column range that changed (None = full width)
dirty: Set of dirty row indices
"""
rows: tuple[int, int] | None = None # (start, end) inclusive
cols: tuple[int, int] | None = None # (start, end) inclusive
dirty: set[int] | None = None # Set of dirty row indices
full_buffer: bool = True # If True, process entire buffer
@dataclass
class EffectContext:
terminal_width: int
@@ -101,6 +120,7 @@ class EffectPlugin(ABC):
name: str
config: EffectConfig
param_bindings: dict[str, dict[str, str | float]] = {}
supports_partial_updates: bool = False # Override in subclasses for optimization
@abstractmethod
def process(self, buf: list[str], ctx: EffectContext) -> list[str]:
@@ -115,6 +135,25 @@ class EffectPlugin(ABC):
"""
...
def process_partial(
self, buf: list[str], ctx: EffectContext, partial: PartialUpdate
) -> list[str]:
"""Process a partial buffer for optimized rendering.
Override this in subclasses that support partial updates for performance.
Default implementation falls back to full buffer processing.
Args:
buf: List of lines to process
ctx: Effect context with terminal state
partial: PartialUpdate indicating which regions changed
Returns:
Processed buffer (may be same object or new list)
"""
# Default: fall back to full processing
return self.process(buf, ctx)
@abstractmethod
def configure(self, config: EffectConfig) -> None:
"""Configure the effect with new settings.