memoize the signals

This commit is contained in:
Evan Carroll 2026-01-26 23:50:19 -06:00
parent a4cf8d3df4
commit e8ca7c9a12
2 changed files with 10 additions and 8 deletions

View file

@ -27,7 +27,7 @@ use super::canvas_utils::normalize_asset_path;
/// Screen boundaries for visual clamping in screen space. /// Screen boundaries for visual clamping in screen space.
/// ///
/// Used by Avatar for clamping avatar positions and bubble positions. /// Used by Avatar for clamping avatar positions and bubble positions.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct ScreenBounds { pub struct ScreenBounds {
/// Left edge of drawable area (= offset_x) /// Left edge of drawable area (= offset_x)
pub min_x: f64, pub min_x: f64,
@ -82,7 +82,7 @@ impl ScreenBounds {
/// Transform parameters for converting scene coordinates to screen coordinates. /// Transform parameters for converting scene coordinates to screen coordinates.
/// ///
/// Used by Avatar and LoosePropCanvas to position elements on screen. /// Used by Avatar and LoosePropCanvas to position elements on screen.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct SceneTransform { pub struct SceneTransform {
/// X scale factor (screen pixels per scene unit) /// X scale factor (screen pixels per scene unit)
pub scale_x: f64, pub scale_x: f64,

View file

@ -444,16 +444,17 @@ pub fn RealmSceneViewer(
let text_em_size = Signal::derive(move || settings.get().text_em_size); let text_em_size = Signal::derive(move || settings.get().text_em_size);
// Compute SceneTransform once for all avatars and props // Compute SceneTransform once for all avatars and props (memoized)
let scene_transform = Signal::derive(move || SceneTransform { let scene_transform: Signal<SceneTransform> = Memo::new(move |_| SceneTransform {
scale_x: scale_x.get(), scale_x: scale_x.get(),
scale_y: scale_y.get(), scale_y: scale_y.get(),
offset_x: offset_x.get(), offset_x: offset_x.get(),
offset_y: offset_y.get(), offset_y: offset_y.get(),
}); })
.into();
// Compute ScreenBounds once for all avatars (for clamping) // Compute ScreenBounds once for all avatars (memoized for clamping)
let screen_bounds = Signal::derive(move || { let screen_bounds: Signal<ScreenBounds> = Memo::new(move |_| {
let t = scene_transform.get(); let t = scene_transform.get();
ScreenBounds::from_transform( ScreenBounds::from_transform(
scene_width_f, scene_width_f,
@ -463,7 +464,8 @@ pub fn RealmSceneViewer(
t.offset_x, t.offset_x,
t.offset_y, t.offset_y,
) )
}); })
.into();
let members_by_key = Signal::derive(move || { let members_by_key = Signal::derive(move || {
sorted_members.get().into_iter().enumerate() sorted_members.get().into_iter().enumerate()