Raxol.Core.Performance.Caches.ComponentRenderCache (Raxol v2.0.1)

View Source

High-performance cache for component rendering results.

This module caches rendered component output to avoid repeated rendering of components with identical state and props. Components are frequently re-rendered during UI updates, and caching can significantly reduce computational overhead.

Features

  • Caches component render results based on state+props hash
  • Caches composed render trees
  • Caches element-to-cell conversions
  • Thread-safe concurrent access via ETS
  • Telemetry instrumentation for monitoring

Performance Impact

Expected improvements:

  • 50-70% reduction in component rendering overhead
  • Sub-microsecond access for cached renders
  • Significant reduction in CPU usage for static components

Summary

Functions

Estimates the render cost of a component to determine caching strategy.

Gets the composed render tree from cache or composes and caches it.

Gets the rendered cells for an element from cache or renders and caches them.

Gets the rendered element from cache or renders and caches it.

Gets the rendered output for a component from cache or renders and caches it.

Invalidates cache entries for a specific component.

Checks if a component render would benefit from caching. Returns true if the component is complex enough to warrant caching.

Warms up the cache with common component renders.

Functions

estimate_render_cost(arg1)

@spec estimate_render_cost(map()) :: :low | :medium | :high

Estimates the render cost of a component to determine caching strategy.

get_composed_tree(layout_data, new_tree, previous_tree)

@spec get_composed_tree(term(), term(), term()) :: term()

Gets the composed render tree from cache or composes and caches it.

get_element_cells(element, theme \\ nil)

@spec get_element_cells(map(), map() | nil) :: list()

Gets the rendered cells for an element from cache or renders and caches them.

get_rendered_element(element, theme, parent_style \\ %{})

@spec get_rendered_element(map(), map(), map()) :: list()

Gets the rendered element from cache or renders and caches it.

get_rendered_output(component_module, state, props)

@spec get_rendered_output(module(), map(), map()) :: term()

Gets the rendered output for a component from cache or renders and caches it.

invalidate_component(component_module, state_or_all \\ :all)

@spec invalidate_component(module(), map() | :all) :: :ok

Invalidates cache entries for a specific component.

should_cache?(arg1)

@spec should_cache?(map() | term()) :: boolean()

Checks if a component render would benefit from caching. Returns true if the component is complex enough to warrant caching.

warmup(component_specs)

@spec warmup([{module(), map(), map()}]) :: :ok

Warms up the cache with common component renders.