fix: offload map parsing to worker thread to prevent event loop blocking - #966
Open
allenporter wants to merge 1 commit into
Open
allenporter wants to merge 1 commit into
allenporter wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Concurrent refreshes can apply stale map data; serialization or generation checks are needed.
Review effort: Lite
Findings: None
What changed in this PR
This pull request offloads V1 map parsing and rendering to worker threads to reduce asyncio event-loop blocking.
Changes:
- Runs map conversion via
asyncio.to_thread. - Adds threaded cached-map parsing.
- Reuses unchanged cached map content.
| File | Description |
|---|---|
roborock/devices/traits/v1/map_content.py |
Offloads map conversion to a worker thread. |
roborock/devices/traits/v1/home.py |
Offloads cached parsing and avoids redundant reparsing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
allenporter
force-pushed
the
fix-blocking-map-parsing
branch
from
September 20, 2026 19:17
b213233 to
10bbbda
Compare
allenporter
commented
Sep 20, 2026
allenporter
force-pushed
the
fix-blocking-map-parsing
branch
from
September 20, 2026 19:22
10bbbda to
b925c8d
Compare
allenporter
marked this pull request as draft
September 20, 2026 19:29
allenporter
commented
Sep 20, 2026
allenporter
force-pushed
the
fix-blocking-map-parsing
branch
from
September 20, 2026 19:33
b925c8d to
6f4275a
Compare
Offload CPU-intensive map parsing and rendering to worker threads via `asyncio.to_thread` to prevent blocking the asyncio event loop. - In `MapContentTrait.refresh()`, offload `self.converter.convert` to `asyncio.to_thread`. - In `HomeTrait.discover_home()`, move cached map parsing to a helper function `_parse_cached_home_map_content` and run it via `asyncio.to_thread`. - Avoid reparsing cached maps in `HomeTrait` when raw bytes are unchanged. Addresses home-assistant/core#182656
allenporter
force-pushed
the
fix-blocking-map-parsing
branch
from
September 20, 2026 19:35
6f4275a to
377d0ec
Compare
allenporter
marked this pull request as ready for review
September 20, 2026 20:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Offload CPU-intensive map parsing and rendering to worker threads via
asyncio.to_threadto prevent blocking the asyncio event loop.When devices are actively cleaning and returning map updates, parsing the raw map payload and rendering the map into PNG format runs synchronously on the asyncio event loop. In multi-device setups or frequent update cycles, this locks the event loop and leads to high latency spikes in downstream consumers like Home Assistant (see home-assistant/core#182656).
Changes
MapContentTrait.refresh(): offloadself.converter.convert(response)to a worker thread usingawait asyncio.to_thread(self.converter.convert, response).HomeTrait:_parse_cached_home_map_content(...)and run it viaawait asyncio.to_thread(...)once, rather than runningasyncio.to_threadper item in a loop._parse_cached_home_map_contentwhen the cached bytes match the previously parsedraw_api_response.Fixes home-assistant/core#182656