Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

TL13a: a page's rects taken with less work. blitz-dom transformed_rect first walks the containing-block chain without matrix math and answers None at once when no node on it has a transform or projection (the full walk then never multiplies a non-identity in and returns None too, so every answer is the same); it was the busiest leaf of a 400-clip timeline drag in raea's window, as every element's rect is taken each frame for the twins' boxes and the JS layout snapshot. raea-runtime-twins: RAEA_TWIN_SYNC_LIGHT=1 (a trial, off by default) has an event's sync_twins keep a kept twin's box rather than take every element's rect again on each pointer move: layout has not run since the frame's own twins pass took them, and that pass takes them again after this frame's layout; a new twin still takes its box at once. Unset, the sync takes every box as before

shinyobjectzd5b8b9ab356f
diff --git a/runtime/twins/src/bridge.rs b/runtime/twins/src/bridge.rs
index 5affc041..c505add7 100644
--- a/runtime/twins/src/bridge.rs
+++ b/runtime/twins/src/bridge.rs
@@ -198,7 +198,7 @@ impl<R: OpIds> Plugin for BridgePlugin<R> {
.add_message::<PageConflict>()
.configure_sets(PreUpdate, PageSystems::Step.after(PageSystems::Events).after(bevy::picking::PickingSystems::Last))
.configure_sets(PostUpdate, (PageSystems::Commands, PageSystems::Restyle, PageSystems::Layout, PageSystems::Twins, PageSystems::Paint).chain())
- .add_systems(PostUpdate, (apply_commands.in_set(PageSystems::Commands), twins::<R>.in_set(PageSystems::Twins)));
+ .add_systems(PostUpdate, (apply_commands.in_set(PageSystems::Commands), twins::<R, true>.in_set(PageSystems::Twins)));
}
}
@@ -221,8 +221,9 @@ fn elements(doc: &BaseDocument, ops: Option<&HashMap<u64, NodeId>>, out: &mut Ve
}
/// Twins spawned for new elements and despawned with theirs (and with their page), and each one's box written when it
-/// changed (H1). A twin's components are the page's (H9): one a system wrote is put back, named.
-fn twins<R: OpIds>(
+/// changed (H1). A twin's components are the page's (H9): one a system wrote is put back, named. Without `BOXES` (an
+/// event's sync, under RAEA_TWIN_SYNC_LIGHT) a kept twin keeps the box it has: only a new one takes its box now.
+fn twins<R: OpIds, const BOXES: bool>(
mut commands: Commands,
docs: NonSend<Docs>,
roots: Option<NonSend<R>>,
@@ -260,11 +261,12 @@ fn twins<R: OpIds>(
by_key.clear();
t.by_node.clear();
for (key, node) in now.drain(..) {
- let at = doc.get_client_bounding_rect(node).map(|b| ElementBox(Rect::new(b.x as f32, b.y as f32, (b.x + b.width) as f32, (b.y + b.height) as f32))).unwrap_or_default();
+ let rect = || doc.get_client_bounding_rect(node).map(|b| ElementBox(Rect::new(b.x as f32, b.y as f32, (b.x + b.width) as f32, (b.y + b.height) as f32))).unwrap_or_default();
let op = if let Key::Op(id) = key { Some(id) } else { plain.0.get(page).and_then(|m| m.get(&node)).copied() };
let el_now = PageElement { page: *page, node, op };
- let e = match t.by_key.remove(&key) {
+ let (e, at) = match t.by_key.remove(&key) {
Some(e) => {
+ let mut kept = None;
if let Ok((mut el, mut b)) = twins.get_mut(e) {
if let Some((was_el, was_b)) = t.written.get(&e) {
if *el != *was_el {
@@ -275,11 +277,17 @@ fn twins<R: OpIds>(
}
}
el.set_if_neq(el_now);
+ // an event's sync leaves the box to the frame's own pass, which takes it after layout
+ let at = if BOXES || !light_sync() { rect() } else { *b };
b.set_if_neq(at);
+ kept = Some(at);
}
- e
+ (e, kept.unwrap_or_else(rect))
+ }
+ None => {
+ let at = rect();
+ (commands.spawn((el_now, at)).id(), at)
}
- None => commands.spawn((el_now, at)).id(),
};
t.written.insert(e, (el_now, at));
by_key.insert(key, e);
@@ -445,11 +453,20 @@ impl<H: EventHandler> EventHandler for Forward<'_, H> {
/// for the event's path and for whatever runs in the frame after it (its box comes at [`PageSystems::Twins`]).
/// The twins brought to the pages now, outside their set: before an event's delivery, after a host step's commits.
pub fn sync_twins<R: OpIds>(world: &mut World) {
- if let Err(e) = world.run_system_cached(twins::<R>) {
+ if let Err(e) = world.run_system_cached(twins::<R, false>) {
warn!("raea-page: twins: {e}");
}
}
+/// RAEA_TWIN_SYNC_LIGHT=1 (a trial, off by default): an event's sync spawns and despawns twins and sets their
+/// hierarchy, but leaves a kept twin's box as it is. Layout hasn't run since the frame's own pass took every box, and
+/// that pass takes them again after this frame's layout; taking each element's rect on every pointer move was most of
+/// a 400-clip timeline drag's twin work (docs/timeline.feature TL13a).
+fn light_sync() -> bool {
+ static ON: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| std::env::var_os("RAEA_TWIN_SYNC_LIGHT").is_some_and(|v| v == "1"));
+ *ON
+}
+
pub fn deliver<R: OpIds>(world: &mut World, page: Entity, fired: Vec<Fired>) {
if fired.is_empty() {
return;
diff --git a/vendor/blitz-dom/src/document.rs b/vendor/blitz-dom/src/document.rs
index bf626462..93ac21ba 100644
--- a/vendor/blitz-dom/src/document.rs
+++ b/vendor/blitz-dom/src/document.rs
@@ -2563,6 +2563,22 @@ impl BaseDocument {
/// on its containing block chain, projections included, as transformed_bounds takes its border box; None when
/// there's no transform on it (the render manifest's ink: the span of a line's letters on a turned card)
pub fn transformed_rect(&self, node_id: NodeId, rect: [f64; 4]) -> Option<BoundingRect> {
+ // raea: most chains carry no transform and no projection, and then the walk below multiplies a matrix at every
+ // step only to answer None. Asked first without the math (a page's every element's rect is taken each frame:
+ // the twins' boxes and the JS's layout snapshot; with 400 timeline clips this was the frame's busiest leaf)
+ let mut c = Some(node_id);
+ let mut any = false;
+ while let Some(id) = c {
+ let Some(node) = self.nodes.get(id) else { break };
+ if self.projections.contains_key(&id) || node.transform().is_some() {
+ any = true;
+ break;
+ }
+ c = node.containing_block();
+ }
+ if !any {
+ return None;
+ }
// a 3x3 on column vectors (x, y, w), row-major, in CSS px
type H = [f64; 9];
fn mul(a: &H, b: &H) -> H {