Elucidation / mapf-multiagent-robot-planning

Multi-Agent PathFinding (MAPF) for 2D Robots moving inventory on a grid - Practice building environment + robots + planning + inventory management etc.
MIT License
11 stars 3 forks source link

Break up svg robots update into multiple tasks #115

Open Elucidation opened 1 year ago

Elucidation commented 1 year ago

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

Elucidation commented 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.

image

Elucidation commented 1 year ago

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.

image

Elucidation commented 1 year ago

Unrelated, want to stop updating held item text every time as that causes a recalc

Elucidation commented 1 year ago

Also consider shape-rendering optimizespeed https://codepen.io/tigt/post/improving-svg-rendering-performance

Elucidation commented 1 year ago

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

Elucidation commented 1 year ago

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

Elucidation commented 1 year ago

Some quick profiling shows for transform setting robot positions:

  1. svg_robot.transform.baseVal[0].setTranslate(x,y) takes ~1.112 us
  2. svg_robot.setAttribute("transform",translate(${x}, ${y})) takes ~1.975 us

Or about 77.61% faster.