From e3148ea20e02bcb4d0764bfb93dc841938325c7b Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 23 Jan 2026 13:34:19 +0100 Subject: [PATCH] :tada: Adding performance logs flag --- common/src/app/common/flags.cljc | 2 + frontend/src/app/main/data/event.cljs | 71 ++++++++++++++------------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/common/src/app/common/flags.cljc b/common/src/app/common/flags.cljc index 8c26778e90..b7b5e18f7c 100644 --- a/common/src/app/common/flags.cljc +++ b/common/src/app/common/flags.cljc @@ -134,6 +134,8 @@ :subscriptions :subscriptions-old :inspect-styles + ;; Enable performance logs in devconsole (disabled by default) + :perf-logs ;; Security layer middleware that filters request by fetch ;; metadata headers diff --git a/frontend/src/app/main/data/event.cljs b/frontend/src/app/main/data/event.cljs index 41daafdda6..7ee1d63225 100644 --- a/frontend/src/app/main/data/event.cljs +++ b/frontend/src/app/main/data/event.cljs @@ -476,23 +476,24 @@ (when (and (some? (.-PerformanceObserver js/window)) (nil? @longtask-observer*)) (let [observer (js/PerformanceObserver. (fn [list _] - (doseq [entry (.getEntries list)] - (let [dur (.-duration entry) - start (.-startTime entry) - attrib (.-attribution entry) - attrib-count (when attrib (.-length attrib)) - first-attrib (when (and attrib-count (> attrib-count 0)) (aget attrib 0)) - attrib-name (when first-attrib (.-name first-attrib)) - attrib-ctype (when first-attrib (.-containerType first-attrib)) - attrib-cid (when first-attrib (.-containerId first-attrib)) - attrib-csrc (when first-attrib (.-containerSrc first-attrib))] + (when (contains? cf/flags :perf-logs) + (doseq [entry (.getEntries list)] + (let [dur (.-duration entry) + start (.-startTime entry) + attrib (.-attribution entry) + attrib-count (when attrib (.-length attrib)) + first-attrib (when (and attrib-count (> attrib-count 0)) (aget attrib 0)) + attrib-name (when first-attrib (.-name first-attrib)) + attrib-ctype (when first-attrib (.-containerType first-attrib)) + attrib-cid (when first-attrib (.-containerId first-attrib)) + attrib-csrc (when first-attrib (.-containerSrc first-attrib))] - (.warn js/console (str "[perf] long task " (Math/round dur) "ms at " (Math/round start) "ms" - (when first-attrib - (str " attrib:name=" attrib-name - " ctype=" attrib-ctype - " cid=" attrib-cid - " csrc=" attrib-csrc))))))))] + (.warn js/console (str "[perf] long task " (Math/round dur) "ms at " (Math/round start) "ms" + (when first-attrib + (str " attrib:name=" attrib-name + " ctype=" attrib-ctype + " cid=" attrib-cid + " csrc=" attrib-csrc)))))))))] (.observe observer #js{:entryTypes #js["longtask"]}) (reset! longtask-observer* observer)))) @@ -505,28 +506,30 @@ (let [last (atom (.now js/performance)) id (js/setInterval (fn [] - (let [now (.now js/performance) - expected (+ @last interval-ms) - drift (- now expected) - current-op @current-op* - measures (.getEntriesByType js/performance "measure") - mlen (.-length measures) - last-measure (when (> mlen 0) (aget measures (dec mlen))) - meas-name (when last-measure (.-name last-measure)) - meas-detail (when last-measure (.-detail last-measure)) - meas-count (when meas-detail (unchecked-get meas-detail "count"))] - (reset! last now) - (when (> drift threshold-ms) - (.warn js/console - (str "[perf] event loop stall: " (Math/round drift) "ms" - (when current-op (str " op=" current-op)) - (when meas-name (str " last=" meas-name)) - (when meas-count (str " count=" meas-count))))))) + (when (contains? cf/flags :perf-logs) + (let [now (.now js/performance) + expected (+ @last interval-ms) + drift (- now expected) + current-op @current-op* + measures (.getEntriesByType js/performance "measure") + mlen (.-length measures) + last-measure (when (> mlen 0) (aget measures (dec mlen))) + meas-name (when last-measure (.-name last-measure)) + meas-detail (when last-measure (.-detail last-measure)) + meas-count (when meas-detail (unchecked-get meas-detail "count"))] + (reset! last now) + (when (> drift threshold-ms) + (.warn js/console + (str "[perf] event loop stall: " (Math/round drift) "ms" + (when current-op (str " op=" current-op)) + (when meas-name (str " last=" meas-name)) + (when meas-count (str " count=" meas-count)))))))) interval-ms)] (reset! stall-timer* id)))) (defn init! - "Install perf observers in dev builds. Safe to call multiple times." + "Install perf observers in dev builds. Safe to call multiple times. + Perf logs are disabled by default. Enable them with the :perf-logs flag in config." [] (when ^boolean js/goog.DEBUG (install-long-task-observer!)