Skip to content

fix(ledmatrix-music): skip websocket UTF-8 validation on the YTM socket (1.5.3) - #602

Merged
ChuckBuilds merged 1 commit into
mainfrom
fix/music-ytm-skip-utf8
Oct 3, 2026
Merged

ChuckBuilds merged 1 commit into
mainfrom
fix/music-ytm-skip-utf8

Conversation

@ChuckBuilds

Copy link
Copy Markdown
Owner

Summary

Scrolling stutters on the whole panel while YouTube Music is playing. The YTM Companion pushes its full player state (~59 KB, almost all of it the play queue) every few seconds, and websocket-client validates each text frame's UTF-8 in pure Python unless wsaccel is installed, holding the GIL for ~30 ms per push on a Pi 4. This passes skip_utf8_validation through socketio.Client(websocket_extra_options=...). The payload is still decoded and parsed as JSON, which rejects anything malformed.

Type of change

  • Bug fix in an existing plugin

Plugin(s) affected

ledmatrix-music (1.5.2 → 1.5.3)

Test plan

  • Loaded the plugin in LEDMatrix on real hardware: hdpi (Pi 4, 512x64), core main @ 5aa7a631
  • Evidence for the cause, from hdpi:
    • py-spy record --gil with music playing: ~16% of the display process's GIL time in websocket/_utils.py _validate_utf8 / _decode, on the Socket.IO read thread
    • scroll stalls went from ~0.6% of frames to 6–8.5% (p95 13 ms → 30–40 ms) for exactly the minutes YTM events were arriving, and back to 0.6% when they stopped
    • on the live payload (59,350 bytes): pure-Python validate_utf8 29.8 ms, json.loads 1.0 ms
  • New test_ytm_skip_utf8_validation.py pins the option on the client; test_ytm_reconnect_backoff.py still passes
  • python-socketio>=5.11 already requires python-engineio>=4.8.0, whose Client accepts websocket_extra_options (checked in the 4.8.0 wheel)

Notes for reviewer

wsaccel would also fix it, but only where someone installs it; this fixes it for every install.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1608c6cc-236e-43e4-9173-38639bf13641
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@ChuckBuilds

Copy link
Copy Markdown
Owner Author

Verified on hdpi (Pi 4, 512x64) with 1.5.3 deployed and music playing: from 12:24 to 12:31 the YTM socket delivered 11-17 events a minute, and scroll stalls were 0.89% of frames (11,697 frames over the minutes that scrolled), against 6-8.5% with 1.5.2 under the same conditions and ~0.6% with no music. Only about 3 minutes of scrolling fell in that window, but the gap is well clear of noise.

…et (1.5.5)

websocket-client validates every text frame's UTF-8 in pure Python unless
wsaccel is installed, and holds the GIL while it does. The YTM Companion
pushes its whole player state (~59KB, mostly the queue) every few seconds
while music plays. On hdpi (512x64, Pi 4) a py-spy --gil profile put ~16% of
the display process's GIL time in websocket/_utils.py _validate_utf8/_decode,
and scroll stalls rose from ~0.6% of frames to ~8.5% from the moment the
socket connected; with this change they were 0.89% with music playing.

Pass skip_utf8_validation through socketio.Client's
websocket_extra_options (engineio >= 4.8, already implied by the
python-socketio>=5.11 floor). The payload is still decoded and parsed as
JSON, which rejects anything malformed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BkfgXMqqwn2w4NN7LRzhxy
@ChuckBuilds
ChuckBuilds force-pushed the fix/music-ytm-skip-utf8 branch from d122ff4 to 690721b Compare October 3, 2026 16:11
@ChuckBuilds
ChuckBuilds merged commit 61ec727 into main Oct 3, 2026
4 checks passed
@ChuckBuilds
ChuckBuilds deleted the fix/music-ytm-skip-utf8 branch October 3, 2026 16:14
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