Skip to content

perf(map): optimize adjacency-aware room color calculation with LUT - #972

Open
allenporter wants to merge 1 commit into
Python-roborock:mainfrom
allenporter:perf-room-colors-lut
Open

allenporter wants to merge 1 commit into
Python-roborock:mainfrom
allenporter:perf-room-colors-lut

Conversation

@allenporter

@allenporter allenporter commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Optimizes adjacency_aware_room_colors in roborock/map/room_colors.py:

  1. Precomputes a 256-entry lookup table for room_id_from_cell byte conversions, avoiding hundreds of thousands of dynamic callback invocations per grid pass.
  2. Adds a fast-path comparison (neighbor_val != value) to immediately skip adjacent cells with identical pixel values (which belong to the same room).

Performance Impact (Benchmarked on 200x200 grid)

  • adjacency_aware_room_colors standalone: 14.85 ms $\rightarrow$ 4.69 ms (3.2x faster)
  • Full composite render (Scale 4, 800x800): 36.50 ms $\rightarrow$ 28.24 ms (23% faster)
  • Full composite render (Scale 1, 200x200): 22.15 ms $\rightarrow$ 14.28 ms (36% faster)
Metric Before After Change
adjacency_aware_room_colors 14.85 ms 4.69 ms 3.2x faster (-68.4%)
Full Render (Scale 4, 800x800) 36.50 ms 28.24 ms -8.26 ms (-22.6%)
Full Render (Scale 1, 200x200) 22.15 ms 14.28 ms -7.87 ms (-35.5%)

Verification

  • All 123 map tests and syrupy snapshots pass unchanged (uv run pytest tests/map/).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Benchmark statistics, CLI validation, and type-checking dependency issues remain unresolved.

Review effort: Lite
Findings: 3 Medium severity

Open (3)
What changed in this PR

Optimizes Q10 map rendering and room-color adjacency processing while adding benchmark tooling.

Changes:

  • Adds LUT-based room lookup and adjacency fast paths.
  • Uses PIL palette-mode rasterization.
  • Adds benchmark coverage and profiling support.
File Summary
tests/​map/​test_benchmarks.py Adds benchmark and profiling tooling. Final comments identify inaccurate median/P95 calculations, invalid non-positive iteration handling, and an undeclared pytest-codspeed type-checking dependency.
roborock/​map/​room_colors.py Optimizes adjacency-aware room coloring with LUT conversion and neighbor short-circuiting.
roborock/​map/​b01_q10_map_parser.py Uses palette-mode rendering for faster rasterization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/map/test_benchmarks.py Outdated
Comment thread tests/map/test_benchmarks.py
Comment thread tests/map/test_benchmarks.py
@allenporter
allenporter marked this pull request as draft September 28, 2026 03:46
@allenporter
allenporter force-pushed the perf-room-colors-lut branch 3 times, most recently from c4ecf45 to ad34dc7 Compare October 4, 2026 22:40
@allenporter
allenporter force-pushed the perf-room-colors-lut branch from ad34dc7 to 6d21f5f Compare October 5, 2026 14:17
@allenporter
allenporter force-pushed the perf-room-colors-lut branch from 6d21f5f to 3b71a6b Compare October 5, 2026 14:48
@allenporter
allenporter requested a review from Lash-L October 5, 2026 14:56
@allenporter
allenporter marked this pull request as ready for review October 5, 2026 14:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants