Skip to content

Move ASH handling to a subinterpreter/subprocess - #770

Draft
puddly wants to merge 3 commits into
zigpy:devfrom
puddly:puddly/event-loop-proxy-subinterpreter
Draft

puddly wants to merge 3 commits into
zigpy:devfrom
puddly:puddly/event-loop-proxy-subinterpreter

Conversation

@puddly

@puddly puddly commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

This is an alternative approach to ASH auto-ACKing.

Our current approach of using a second thread for the event loop is unfortunately flawed: when the main thread has GC stutters, so does the gateway thread. This can get bad enough to still trigger ASH resets. We can use a subinterpreter (3.14+) or subprocess as a parallelism mechanism that is more isolated than a thread.

It's comparable to threading for all of the happy paths.


Measurement Thread Subprocess Subinterpreter In-process
20 ms timer p99 under main-interpreter GC storm (3.14) 170 ms 2.5 ms 4.2 ms n/a
20 ms timer max under GC storm (3.14) 185 ms 18 ms 8.4 ms n/a
20 ms timer p99 under GC storm (3.15.0b1) – – 2.7 ms n/a
Bridge round trip, trivial call, p50 66 µs – 73 µs 0.1 µs
Bridge round trip, trivial call, p99 102 µs – 162 µs 0.2 µs
send_data with NCP ACK over TCP, p50 226 µs – 260 µs 138 µs
send_data with NCP ACK over TCP, p99 399 µs – 382 µs 253 µs
Startup cost ~0 ~0.3 s ~0.13 s 0
Memory cost ~0 ~50 MB ~20 MB 0

GC storm: 3 million object heap in the main interpreter, gc.collect() every 0.5 s, each collection ~180 ms.

Related: #753
Related: #766
Related: #735

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.22222% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.00%. Comparing base (aea9248) to head (18b2c23).

Files with missing lines Patch % Lines
bellows/uart.py 91.53% 27 Missing ⚠️
bellows/ezsp/__init__.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #770      +/-   ##
==========================================
- Coverage   99.58%   99.00%   -0.58%     
==========================================
  Files          64       63       -1     
  Lines        4331     4540     +209     
==========================================
+ Hits         4313     4495     +182     
- Misses         18       45      +27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@puddly puddly changed the title Move ASH handling to a subinterpreter Move ASH handling to a subinterpreter/subprocess Oct 21, 2026
@puddly

puddly commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Ah, there's a fatal problem with this approach... esphome-hass:// does not and cannot work 😅

@puddly

puddly commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

That being said, we will need to come up with a solution to esphome-hass:// when ZHA moves into its own app either way. By that point, something like this will not be needed.

@zigpy-review-bot zigpy-review-bot added the code quality Improvement to code quality label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Improvement to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants