When a user is viewing the Map, the page tends to peg a few cores. One of the culprits appears to be the iterating of results from a call to /api/data, which returns the summary of everything for each thing in the grid.
A suggestion, if that’s correct - Add an optional timestamp to the /api/data call as a parameter. If no timestamp is given, /api/data returns world+dog as it presently does, and use that for the initial drawing. If a timestamp is provided, only return stuff that’s new since that timestamp. Other than an initial call when the map is given focus, all calls would include the timestamp of when the prior update’s GET was started. If the user leaves the map for something else (scheduler, Logbook, etc), and then comes back, just start over with a no-timestamp call.
Obviously the db needs to track lastmodified, internally. But I’m pretty sure that already exists.
Other than the initial call, this means the javascript won’t be trying to update 1,827,3927,481 cells with 30+ fly-out text objects that are basically static once drawn, aside from the two or three that Yarbo visited since last update. Subsequent calls would only return details for those two or three grids, and only they get updated / drawn.
Can probably do a similar strategy with api/alerts as well.
Thanks for this, it’s a good idea and we see your point. While the robot is working, the map is sent in full on every refresh, even though only a few squares have changed.
We’re going to put a small twist on it. Instead of asking for everything since a timestamp, the page will tell Yardstick which version of the map it already has, and Yardstick will send only what changed since that version. The reason is that readings don’t always arrive in order: a robot that drops off Wi-Fi or 4G can send a batch of older readings when it reconnects. “Since a timestamp” would miss those, while “since the version you have” can’t. If Yardstick can’t be sure, it simply sends the whole map, so the map is never wrong.
Thanks again for the suggestion. We’re actually in the middle of a build cycle right now and plan on running it up and sending it into testing later today or tomorrow.
Might want to look at version optimization for the zones returned in /api/data at some point, can probably claw back a bunch of server-side CPU that isn’t needed. My poor little pi4 is taking up to 15 seconds to reply on some calls, and those seem to be ones that reply with all of the zone polygons. While the pi is building the response, the pi seems to bog on subsequent status/position/etc calls until the data invocation is complete. Your ‘version’ strategy might rock that, if it applies.
Thanks for flagging this, and you were right that the Pi was doing work it didn’t need to. We loaded a big history onto our own Pi 4 and saw the same thing: after Yarbo sent a few new readings, the next map refresh took several seconds, and status calls waited behind it.
It turned out not to be the zones, which take about a millisecond. The time was going into redrawing Yarbo’s whole driven track on every refresh, and for ranges like Today or Last 7 days, re-reading every reading in the range. The next build fixes both: each refresh now adds only what’s new.
Here is what we measured on our Pi 4, refreshing the map after Yarbo sent 50 new readings:
Before
After
Map, All time
5 to 9 seconds
0.1 seconds
Map, Last 7 days
about 20 seconds
under 1 second
Status call while the map refreshes
3.5 seconds
under 0.5 seconds
It’ll be in the next release. Thanks again, this one made a real difference.