From 25923966ebe3fb2906d89da1375f85db8613eadc Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 26 Nov 2026 18:44:24 -0500 Subject: [PATCH] perf(hud): read thermal zone types once instead of on every refresh (#3304) * Read thermal zone types once for the HUD Every HUD refresh listed /sys/class/thermal and opened every zone's type file three or four times (CPU temperature, GPU temperature and the replaced-zone check). Zone types do not change while the device runs, so the sorted map is read once and reused. * Cache thermal zone types only after a scan with no read failures --- .../launcher/runtime/LinuxRuntime.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index 279a78530f..fd59297b1f 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -512,7 +512,7 @@ public final class LinuxRuntime { public static List cpuTempZones() { java.util.Map replaced = replacedZoneTypes(); List zones = new ArrayList<>(); - for (java.util.Map.Entry zone : new java.util.TreeMap<>(thermalZones()).entrySet()) { + for (java.util.Map.Entry zone : thermalZones().entrySet()) { String type = zone.getKey(); if (type.contains("cpu") && !type.contains("gpu") && !replaced.containsKey(zone.getValue().getName())) { zones.add(zone.getValue()); @@ -555,23 +555,31 @@ public final class LinuxRuntime { private static String thermalZone(String sensor) { java.util.Map zones = thermalZones(); File zone = zones.get(sensor); - for (java.util.Map.Entry e : new java.util.TreeMap<>(zones).entrySet()) { + for (java.util.Map.Entry e : zones.entrySet()) { if (zone == null && e.getKey().contains(sensor)) zone = e.getValue(); } return zone != null ? new File(zone, "temp").getPath() : null; } - private static java.util.Map thermalZones() { + private static volatile java.util.SortedMap thermalZoneTypes; + + private static java.util.SortedMap thermalZones() { + java.util.SortedMap known = thermalZoneTypes; + if (known != null) return known; java.util.Map byType = new java.util.HashMap<>(); File[] zones = new File("/sys/class/thermal").listFiles((dir, n) -> n.startsWith("thermal_zone")); - if (zones == null) return byType; + if (zones == null) return java.util.Collections.emptySortedMap(); + boolean complete = true; for (File zone : zones) { try (java.io.BufferedReader r = new java.io.BufferedReader(new java.io.FileReader(new File(zone, "type")))) { byType.putIfAbsent(String.valueOf(r.readLine()).trim().toLowerCase(java.util.Locale.ROOT), zone); - } catch (IOException ignored) { + } catch (IOException e) { + complete = false; } } - return byType; + java.util.SortedMap sorted = java.util.Collections.unmodifiableSortedMap(new java.util.TreeMap<>(byType)); + if (complete && !sorted.isEmpty()) thermalZoneTypes = sorted; + return sorted; } private static void bindSystemFonts(List cmd, File root) {