diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 7c4c533aaa..0eb0367e1e 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -59,6 +59,9 @@ (def ^:const MAX_BUFFER_CHUNK_SIZE (* 256 1024)) +(def ^:const DEBOUNCE_DELAY_MS 100) +(def ^:const THROTTLE_DELAY_MS 10) + (def dpr (if use-dpr? (if (exists? js/window) js/window.devicePixelRatio 1.0) 1.0)) @@ -873,10 +876,10 @@ (letfn [(do-render [ts] (h/call wasm/internal-module "_set_view_end") (render ts))] - (fns/debounce do-render 100))) + (fns/debounce do-render DEBOUNCE_DELAY_MS))) (def render-pan - (fns/throttle render 10)) + (fns/throttle render THROTTLE_DELAY_MS)) (defn set-view-box [prev-zoom zoom vbox] diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index 4e8ade29d1..2b3038999d 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -34,9 +34,9 @@ pub use fonts::*; pub use images::*; // This is the extra are used for tile rendering. -const VIEWPORT_INTEREST_AREA_THRESHOLD: i32 = 1; +const VIEWPORT_INTEREST_AREA_THRESHOLD: i32 = 2; const MAX_BLOCKING_TIME_MS: i32 = 32; -const NODE_BATCH_THRESHOLD: i32 = 10; +const NODE_BATCH_THRESHOLD: i32 = 3; type ClipStack = Vec<(Rect, Option, Matrix)>; @@ -1734,6 +1734,7 @@ impl RenderState { allow_stop: bool, ) -> Result<(), String> { let mut should_stop = false; + while !should_stop { if let Some(current_tile) = self.current_tile { if self.surfaces.has_cached_tile_surface(current_tile) { @@ -1807,17 +1808,21 @@ impl RenderState { if !self.surfaces.has_cached_tile_surface(next_tile) { if let Some(ids) = self.tiles.get_shapes_at(next_tile) { + let root_ids_map: std::collections::HashMap = root_ids + .iter() + .enumerate() + .map(|(i, id)| (*id, i)) + .collect(); + // We only need first level shapes let mut valid_ids: Vec = ids .iter() - .filter(|id| root_ids.contains(id)) + .filter(|id| root_ids_map.contains_key(id)) .copied() .collect(); // These shapes for the tile should be ordered as they are in the parent node - valid_ids.sort_by_key(|id| { - root_ids.iter().position(|x| x == id).unwrap_or(usize::MAX) - }); + valid_ids.sort_by_key(|id| root_ids_map.get(id).unwrap_or(&usize::MAX)); self.pending_nodes.extend(valid_ids.into_iter().map(|id| { NodeRenderState { @@ -1834,6 +1839,7 @@ impl RenderState { should_stop = true; } } + self.render_in_progress = false; self.surfaces.gc(); diff --git a/render-wasm/src/render/surfaces.rs b/render-wasm/src/render/surfaces.rs index 18e233326f..94c19915fb 100644 --- a/render-wasm/src/render/surfaces.rs +++ b/render-wasm/src/render/surfaces.rs @@ -8,8 +8,8 @@ use super::{gpu_state::GpuState, tiles::Tile, tiles::TileViewbox, tiles::TILE_SI use base64::{engine::general_purpose, Engine as _}; use std::collections::{HashMap, HashSet}; -const TEXTURES_CACHE_CAPACITY: usize = 512; -const TEXTURES_BATCH_DELETE: usize = 32; +const TEXTURES_CACHE_CAPACITY: usize = 1024; +const TEXTURES_BATCH_DELETE: usize = 256; // This is the amount of extra space we're going to give to all the surfaces to render shapes. // If it's too big it could affect performance. const TILE_SIZE_MULTIPLIER: i32 = 2; diff --git a/render-wasm/src/tiles.rs b/render-wasm/src/tiles.rs index eec43f8ba5..7012a2e24b 100644 --- a/render-wasm/src/tiles.rs +++ b/render-wasm/src/tiles.rs @@ -88,6 +88,7 @@ impl TileViewbox { } pub fn is_visible(&self, tile: &Tile) -> bool { + // TO CHECK self.interest_rect.contains(tile) self.visible_rect.contains(tile) } }