mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
fix(perf): cache fonts in sport base classes to avoid disk I/O per frame (#285)
* fix(perf): cache fonts in sport base classes to avoid disk I/O per frame Replace 7 ImageFont.truetype() calls in display methods with cached self.fonts['detail'] lookups. The 4x6-font.ttf at size 6 is already loaded once in _load_fonts() — loading it again on every display() call causes unnecessary disk I/O on each render frame (~30-50 FPS). Files: sports.py (2), football.py (1), hockey.py (2), basketball.py (1), baseball.py (1) Co-Authored-By: 5ymb01 <noreply@github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: trigger CodeRabbit review --------- Co-authored-by: 5ymb01 <5ymb01@users.noreply.github.com> Co-authored-by: 5ymb01 <noreply@github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -329,7 +329,7 @@ class Baseball(SportsCore):
|
|||||||
return
|
return
|
||||||
|
|
||||||
series_summary = game.get("series_summary", "")
|
series_summary = game.get("series_summary", "")
|
||||||
font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
font = self.fonts.get('detail', ImageFont.load_default())
|
||||||
bbox = draw_overlay.textbbox((0, 0), series_summary, font=self.fonts['time'])
|
bbox = draw_overlay.textbbox((0, 0), series_summary, font=self.fonts['time'])
|
||||||
height = bbox[3] - bbox[1]
|
height = bbox[3] - bbox[1]
|
||||||
shots_y = (self.display_height - height) // 2
|
shots_y = (self.display_height - height) // 2
|
||||||
|
|||||||
@@ -201,14 +201,7 @@ class BasketballLive(Basketball, SportsLive):
|
|||||||
|
|
||||||
# Draw records or rankings if enabled
|
# Draw records or rankings if enabled
|
||||||
if self.show_records or self.show_ranking:
|
if self.show_records or self.show_ranking:
|
||||||
try:
|
record_font = self.fonts.get('detail', ImageFont.load_default())
|
||||||
record_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
|
||||||
self.logger.debug(f"Loaded 6px record font successfully")
|
|
||||||
except IOError:
|
|
||||||
record_font = ImageFont.load_default()
|
|
||||||
self.logger.warning(
|
|
||||||
f"Failed to load 6px font, using default font (size: {record_font.size})"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get team abbreviations
|
# Get team abbreviations
|
||||||
away_abbr = game.get("away_abbr", "")
|
away_abbr = game.get("away_abbr", "")
|
||||||
|
|||||||
@@ -308,12 +308,7 @@ class FootballLive(Football, SportsLive):
|
|||||||
|
|
||||||
# Draw records or rankings if enabled
|
# Draw records or rankings if enabled
|
||||||
if self.show_records or self.show_ranking:
|
if self.show_records or self.show_ranking:
|
||||||
try:
|
record_font = self.fonts.get('detail', ImageFont.load_default())
|
||||||
record_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
|
||||||
self.logger.debug(f"Loaded 6px record font successfully")
|
|
||||||
except IOError:
|
|
||||||
record_font = ImageFont.load_default()
|
|
||||||
self.logger.warning(f"Failed to load 6px font, using default font (size: {record_font.size})")
|
|
||||||
|
|
||||||
# Get team abbreviations
|
# Get team abbreviations
|
||||||
away_abbr = game.get('away_abbr', '')
|
away_abbr = game.get('away_abbr', '')
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class HockeyLive(Hockey, SportsLive):
|
|||||||
|
|
||||||
# Shots on Goal
|
# Shots on Goal
|
||||||
if self.show_shots_on_goal:
|
if self.show_shots_on_goal:
|
||||||
shots_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
shots_font = self.fonts.get('detail', ImageFont.load_default())
|
||||||
home_shots = str(game.get("home_shots", "0"))
|
home_shots = str(game.get("home_shots", "0"))
|
||||||
away_shots = str(game.get("away_shots", "0"))
|
away_shots = str(game.get("away_shots", "0"))
|
||||||
shots_text = f"{away_shots} SHOTS {home_shots}"
|
shots_text = f"{away_shots} SHOTS {home_shots}"
|
||||||
@@ -276,14 +276,7 @@ class HockeyLive(Hockey, SportsLive):
|
|||||||
|
|
||||||
# Draw records or rankings if enabled
|
# Draw records or rankings if enabled
|
||||||
if self.show_records or self.show_ranking:
|
if self.show_records or self.show_ranking:
|
||||||
try:
|
record_font = self.fonts.get('detail', ImageFont.load_default())
|
||||||
record_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
|
||||||
self.logger.debug(f"Loaded 6px record font successfully")
|
|
||||||
except IOError:
|
|
||||||
record_font = ImageFont.load_default()
|
|
||||||
self.logger.warning(
|
|
||||||
f"Failed to load 6px font, using default font (size: {record_font.size})"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get team abbreviations
|
# Get team abbreviations
|
||||||
away_abbr = game.get("away_abbr", "")
|
away_abbr = game.get("away_abbr", "")
|
||||||
|
|||||||
@@ -863,12 +863,7 @@ class SportsUpcoming(SportsCore):
|
|||||||
|
|
||||||
# Draw records or rankings if enabled
|
# Draw records or rankings if enabled
|
||||||
if self.show_records or self.show_ranking:
|
if self.show_records or self.show_ranking:
|
||||||
try:
|
record_font = self.fonts.get('detail', ImageFont.load_default())
|
||||||
record_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
|
||||||
self.logger.debug(f"Loaded 6px record font successfully")
|
|
||||||
except IOError:
|
|
||||||
record_font = ImageFont.load_default()
|
|
||||||
self.logger.warning(f"Failed to load 6px font, using default font (size: {record_font.size})")
|
|
||||||
|
|
||||||
# Get team abbreviations
|
# Get team abbreviations
|
||||||
away_abbr = game.get('away_abbr', '')
|
away_abbr = game.get('away_abbr', '')
|
||||||
@@ -1172,12 +1167,7 @@ class SportsRecent(SportsCore):
|
|||||||
|
|
||||||
# Draw records or rankings if enabled
|
# Draw records or rankings if enabled
|
||||||
if self.show_records or self.show_ranking:
|
if self.show_records or self.show_ranking:
|
||||||
try:
|
record_font = self.fonts.get('detail', ImageFont.load_default())
|
||||||
record_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
|
||||||
self.logger.debug(f"Loaded 6px record font successfully")
|
|
||||||
except IOError:
|
|
||||||
record_font = ImageFont.load_default()
|
|
||||||
self.logger.warning(f"Failed to load 6px font, using default font (size: {record_font.size})")
|
|
||||||
|
|
||||||
# Get team abbreviations
|
# Get team abbreviations
|
||||||
away_abbr = game.get('away_abbr', '')
|
away_abbr = game.get('away_abbr', '')
|
||||||
|
|||||||
Reference in New Issue
Block a user