perf: gate perf logs and dedup build_config_update on first message (#8627)

Signed-off-by: Bradley Axen <baxen@squareup.com>
This commit is contained in:
Bradley Axen
2026-04-17 12:43:36 -07:00
committed by GitHub
parent 7fa662bcac
commit 8a51e34891
22 changed files with 544 additions and 285 deletions
+39
View File
@@ -0,0 +1,39 @@
/**
* Gated performance logger for frontend timing instrumentation.
*
* Enabled when any of the following is true:
* - Running under Vite dev (`import.meta.env.DEV`)
* - `localStorage.getItem("goose.perf") === "1"`
*
* Otherwise a no-op, so perf call sites add zero runtime cost in release
* builds for users who have not opted in.
*
* Messages are prefixed with `[perf:<channel>]` by callers; this helper
* is intentionally dumb and forwards the already-formatted string.
*/
function isEnabled(): boolean {
try {
if (import.meta.env?.DEV) return true;
} catch {
// import.meta may be unavailable in some test contexts
}
try {
if (
typeof localStorage !== "undefined" &&
localStorage.getItem("goose.perf") === "1"
) {
return true;
}
} catch {
// localStorage can throw in restricted contexts
}
return false;
}
const enabled = isEnabled();
export function perfLog(message: string): void {
if (!enabled) return;
// eslint-disable-next-line no-console
console.log(message);
}