Repository navigation
perf(map): memoize Q10 room-color palette across map renders - #974
allenporter wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Address calibration cache invalidation and erase-zone rebuilding, benchmark input/percentile handling, and related test coverage.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Improves Q10 map rendering performance by caching base-map data, layers, and calibration across trace updates.
Changes:
- Adds cached base-map rendering and overlay composition.
- Caches Q10 layer decomposition and optimizes room-color calculations.
- Adds map parsing, rendering, and profiling benchmarks.
| File | Summary |
|---|---|
tests/map/test_benchmarks.py |
Adds benchmark utilities; percentile calculation and non-positive iteration handling require correction. |
roborock/map/room_colors.py |
Optimizes room-color adjacency calculations. |
roborock/map/b01_q10_render.py |
Adds reusable base-map rendering and composition. |
roborock/map/b01_q10_map_parser.py |
Caches layers and defers PNG serialization. |
roborock/devices/traits/b01/q10/map.py |
Adds base-map and calibration caching; calibration lifecycle and coverage require changes. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| parser.add_argument("--profile", action="store_true", help="Print cProfile hotspot breakdown for each benchmark") | ||
| args = parser.parse_args() | ||
|
|
||
| _run_benchmarks(iterations=args.iterations, warmup=args.warmup, profile=args.profile) |
e255fad to
d086d5d
Compare
05c3968 to
7c2907b
Compare
7c2907b to
d3ef605
Compare
d3ef605 to
36df1ad
Compare
swastiktawate
left a comment
There was a problem hiding this comment.
Nice perf win. The invalidation points look complete — a new map packet or DPS update clears both the cached base data and the calibration, so trace-only updates are the only path that reuses the cache. The copy.copy chain with the explicit image.data.copy() shows care that overlay drawing can't mutate the cached base. The mock-based test pins the call counts precisely.
36df1ad to
6bf9b6b
Compare
6bf9b6b to
ccfd59e
Compare

Description
During an active cleaning run, the robot pushes
Q10TracePackettrajectory updates every 1–2 seconds, triggeringrender_q10_map. Profiling_render_base_grid(9.03 mson a200×200floorplan atscale=4) shows that94%(8.51 ms) is spent inside_build_palette(adjacency_aware_room_colorsscanning 40,000 grid cells in Python), while PIL's C-levelfrombytes("P"),convert("RGBA"), andresizetake only0.52 ms.This change:
_build_palette(grid, width, *, show_walls, show_rooms) -> byteswith@lru_cache(maxsize=16)and returns the flattened 1,024-byte RGBA palette directly top_img.putpalette(..., rawmode="RGBA").MapContentTraitandrender_q10_map's public signature untouched while bounding cached state to ~41 KB per map (40 KBgrid key +1 KBpalette bytes).Performance Impact
200×200grid):8.51 ms< 0.001 mson repeated trace/overlay renders200×200, scale 4):9.03 ms0.52 ms(17x faster)render_q10_map):0.275 ms0.095 ms(2.9x faster)Verification
uv run pre-commit run --all-filesuv run pytest tests/map/ tests/devices/traits/b01/q10/ tests/conformance/