Skip to content

perf(map): eliminate redundant PNG serialization in Q10 rendering pipeline - #973

Draft
allenporter wants to merge 5 commits into
Python-roborock:mainfrom
allenporter:perf-q10-render-pipeline
Draft

allenporter wants to merge 5 commits into
Python-roborock:mainfrom
allenporter:perf-q10-render-pipeline

Conversation

@allenporter

Copy link
Copy Markdown
Contributor

Description

In render_q10_map, the base packet was previously rendered to PNG bytes via parsed_from_packet. Then, whenever the map contained drawables (charger, trace path, virtual walls, or no-go zones—which is almost always true), _draw_map_content re-serialized the image to PNG bytes a second time, discarding the first PNG bytes.

This change:

  1. Adds B01Q10MapParser.map_data_from_packet(packet) returning MapData with the rendered base Image without performing premature PNG encoding.
  2. In render_q10_map, defers PNG serialization to the end of the pipeline so that images are encoded exactly once.
  3. Keeps parsed_from_packet fully backward-compatible for existing callers.

Note: Stacked on top of #972, #971, and #970.

Performance Impact

  • render_q10_map with drawables (200x200 grid + trace session): 44.59 ms $\rightarrow$ 32.76 ms (~12 ms saved / 26% reduction)
  • Eliminates redundant memory churn and duplicate Image.save invocations on every map update.

Verification

  • All 128 map tests pass (uv run pytest tests/map/).

Copilot AI lite review requested due to automatic review settings September 28, 2026 03:30

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 coverage and percentile reporting need correction before approval.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Optimizes Q10 map rendering by deferring PNG serialization until composition completes, while preserving existing parsing APIs.

Changes:

  • Adds PNG-free MapData rendering.
  • Serializes composed images once.
  • Optimizes room-color lookup.
  • Adds map benchmarks and profiling support.
File Summary
tests/​map/​test_benchmarks.py Adds map benchmarks; composite coverage does not exercise overlays, and the reported P95 calculation is incorrect.
roborock/​map/​room_colors.py Adds lookup-table-based room color resolution.
roborock/​map/​b01_q10_render.py Defers PNG serialization in the rendering pipeline.
roborock/​map/​b01_q10_map_parser.py Separates image construction from PNG encoding while preserving compatibility.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

"""Benchmark Q10 composite rendering on a realistic 200x200 4-room floorplan."""
packet = _build_synthetic_q10_grid(200, 200)
parser = B01Q10MapParser()
result = benchmark(parser.parse_packet, packet)
min_ms = timings[0]
mean_ms = sum(timings) / len(timings)
med_ms = timings[len(timings) // 2]
p95_ms = timings[int(len(timings) * 0.95)]
hCoureau

This comment was marked as resolved.

@allenporter
allenporter force-pushed the perf-q10-render-pipeline branch from 4b9b409 to fc6c0fd Compare October 4, 2026 22:40
@allenporter
allenporter force-pushed the perf-q10-render-pipeline branch from fc6c0fd to 7c59a0b Compare October 5, 2026 14:17

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.

3 participants