Open Elucidation opened 1 year ago
For reference, on dev machine with 1K robots running, tasks regularly exceed 50ms, up to 94ms. Primarily in the svg_update_robots call.
Breaking up the svg_update_robots every 100 robots does help, but we're still getting a lot of style recalculate etc, because this is being done on the main DOM directly, probably it would be better to do this on a doc fragment or something and then at the end push it all at once.
Unrelated, want to stop updating held item text every time as that causes a recalc
Also consider shape-rendering optimizespeed https://codepen.io/tigt/post/improving-svg-rendering-performance
shape-rendering: optimizeSpeed does well, but the real improvement is disabling path drawing. Prefer to disable all paths and do #114 to see paths at times
Huge speedup when not updating held item text // let svg_held_item = svg_robot.children[2]; // svg_held_item.textContent = item_name;
Need to change this from update every frame to on change
Some quick profiling shows for transform setting robot positions:
svg_robot.transform.baseVal[0].setTranslate(x,y)
takes ~1.112 us svg_robot.setAttribute("transform",
translate(${x}, ${y}))
takes ~1.975 usOr about 77.61% faster.
Related to #107 we get long running tasks which is possibly due to svg update robots call updating all 1k robots, can break this up in a few ways detailed in https://web.dev/optimize-long-tasks/#manually-defer-code-execution
The async await yield main seems like one potential approach