perf: HUDTextCache — reuse text SDL textures, skip when HUD hidden

This commit is contained in:
Matteo Benedetto
2026-03-24 12:24:42 +01:00
parent 6ef8f4722c
commit fe39312cfa
3 changed files with 103 additions and 21 deletions
+7 -5
View File
@@ -775,6 +775,7 @@ else:
import sdl2.sdlttf as _ttf9
from r36s_dlna_browser.ui import screens as _screens9, theme as _theme9
_cache9 = _screens9.HUDTextCache()
# ── SDL + TTF init (no vsync so phases are timed cleanly) ────────────
sdl2.SDL_SetHint(b"SDL_VIDEODRIVER", b"kmsdrm,offscreen")
@@ -906,9 +907,9 @@ else:
sdl2.SDL_RenderCopy(_ren9, _tex9, None, _dst9)
_t_video = (time.monotonic() - _t0) * 1e6
# Phase 3 — draw_playback() — all TTF_RenderUTF8_Blended + fill-rects.
# Phase 3 — draw_playback() with texture cache (warm after first frame).
_t0 = time.monotonic()
_screens9.draw_playback(_ren9, _font9, _state9, _layout9, _icons9 or None)
_screens9.draw_playback(_ren9, _font9, _state9, _layout9, _icons9 or None, cache=_cache9)
_t_hud = (time.monotonic() - _t0) * 1e6
# Phase 4 — Present (no vsync → should be near-zero on HW renderer).
@@ -928,6 +929,7 @@ else:
pass
# Cleanup.
_cache9.invalidate()
for _itex_v in _icons9.values():
sdl2.SDL_DestroyTexture(_itex_v)
if _tex9:
@@ -955,9 +957,9 @@ else:
print(" --- Section 9 HUD Timing Report ---")
print(f" Frames measured (excl warmup) : {len(_hud9)}")
_stat9("SDL_UpdateNVTexture (synthetic NV12)", _upload9)
_stat9("SDL_RenderClear+RenderCopy (video)", _video9)
_stat9("draw_playback() — TTF+fills+icons", _hud9)
_stat9("SDL_RenderPresent (no vsync)", _pres9)
_stat9("SDL_RenderClear+RenderCopy (video)", _video9)
_stat9("draw_playback() — cached TTF+fills+icons", _hud9)
_stat9("SDL_RenderPresent (no vsync)", _pres9)
_hud_mean = statistics.mean(_hud9) if _hud9 else 0
_total9_mean = (statistics.mean(_upload9) + statistics.mean(_video9) +