Skip to content

perf(map): vectorize Q10 palette rasterization using PIL P-mode - #971

Open
allenporter wants to merge 1 commit into
Python-roborock:mainfrom
allenporter:perf-q10-palette
Open

allenporter wants to merge 1 commit into
Python-roborock:mainfrom
allenporter:perf-q10-palette

Conversation

@allenporter

@allenporter allenporter commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Vectorizes Q10 palette application in B01Q10MapParser._render using PIL's native P (palette) mode with an RGBA color table converted to RGBA in C, replacing a Python loop that appended 4-byte color tuples across all grid cells.

Performance Impact (Benchmarked on 200x200 grid)

  • Pixel rasterization: 7.09 ms $\rightarrow$ 0.11 ms (64x faster)
  • Full composite render (Scale 4, 800x800): 36.94 ms $\rightarrow$ 31.39 ms (15% overall latency reduction)
  • Full composite render (Scale 1, 200x200): 22.15 ms $\rightarrow$ 17.18 ms (22% overall latency reduction)
Metric Before After Change
Scale 4 Median (ms) 36.50 ms 31.45 ms -5.05 ms (-13.8%)
Scale 4 Mean (ms) 36.94 ms 31.39 ms -5.55 ms (-15.0%)
Scale 1 Median (ms) 22.15 ms 17.18 ms -4.97 ms (-22.4%)
Rasterization Standalone 7.09 ms 0.11 ms 64x faster

Verification

  • All existing Q10 tests and rendering snapshots pass unchanged (uv run pytest tests/map/test_b01*).

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 input validation and reported median/percentile calculations need correction.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Optimizes Q10 map rasterization with Pillow palette mode and adds benchmark/profiling coverage.

Changes:

  • Replaces per-cell RGBA construction with native indexed palette conversion.
  • Adds Q10/V1 parsing and rendering benchmarks.

Review findings:

  • tests/map/test_benchmarks.py:196 — Moderate (2 votes): reject iteration counts below one.
  • tests/map/test_benchmarks.py:166 — Moderate (1 vote): calculate the median and 95th percentile correctly.
  • tests/map/test_benchmarks.py:166–167 — Moderate (2 votes): use the standard two-point median for even sample counts.
File Summary
tests/​map/​test_benchmarks.py Adds benchmark and profiling utilities.
roborock/​map/​b01_q10_map_parser.py Vectorizes Q10 palette 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
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-q10-palette branch 3 times, most recently from 9d31449 to 5dbf4cf Compare October 4, 2026 22:39
@allenporter
allenporter marked this pull request as ready for review October 5, 2026 14:54
@allenporter
allenporter requested a review from Lash-L October 5, 2026 14:54

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