Move setPerfTiming next to perfTiming and always capture request start time

Colocate the setter with its variable for readability. Remove the
conditional around performance.now() since the call is negligible
and simplifies the timing logic.
This commit is contained in:
Chris Wanstrath 2026-03-19 11:09:27 -07:00
parent c42c73fe70
commit b9f94a6c98

View File

@ -5,6 +5,8 @@ export type { WsData }
export let perfTiming = false export let perfTiming = false
export const setPerfTiming = (on: boolean) => { perfTiming = on }
const pendingMessages = new Map<ServerWebSocket<WsData>, (string | ArrayBuffer | Uint8Array)[]>() const pendingMessages = new Map<ServerWebSocket<WsData>, (string | ArrayBuffer | Uint8Array)[]>()
const upstreams = new Map<ServerWebSocket<WsData>, WebSocket>() const upstreams = new Map<ServerWebSocket<WsData>, WebSocket>()
@ -14,8 +16,6 @@ interface WsData {
protocols: string[] protocols: string[]
} }
export const setPerfTiming = (on: boolean) => { perfTiming = on }
export function extractSubdomain(host: string): string | null { export function extractSubdomain(host: string): string | null {
// Strip port // Strip port
const hostname = host.replace(/:\d+$/, '') const hostname = host.replace(/:\d+$/, '')
@ -57,7 +57,7 @@ export async function proxySubdomain(subdomain: string, req: Request): Promise<R
headers.delete('transfer-encoding') headers.delete('transfer-encoding')
try { try {
const start = perfTiming ? performance.now() : 0 const start = performance.now()
const res = await fetch(target, { const res = await fetch(target, {
method: req.method, method: req.method,
headers, headers,