Skip to content
Myr

perf(context): drop the throwaway `env` field initializer (#5174)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

`env: E['Bindings'] = {}` allocated an object on every `Context` construction that `#dispatch` immediately overwrote with the real env, so the allocation was wasted on every request. The initializer only ever mattered for `new Context(req)` without options, which now gets its `{}` from the constructor's `else` branch. Semantics are unchanged, including `env` being `undefined` when `options.env` is `undefined`.

authored by Igor Savin · committed by Yusuke Wada · parent e42aac2 · Browse files · 1 file+3 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+3 added−1 removed

  • other:+3 added−1 removed

1 file+3 added−1 removed

modified:src/context.ts+3 added-1 removed
310 unmodified lines
311 * const counter = c.env.COUNTER312 * })313 * ```314 */315 env: E['Bindings'] = {}315 env: E['Bindings']316 #var: Map<unknown, unknown> | undefined317 finalized: boolean = false318 /**319 * `.error` can get the error object from the middleware if the Handler throws an error.
36 unmodified lines
356 this.env = options.env357 this.#notFoundHandler = options.notFoundHandler358 this.#path = options.path359 this.#matchResult = options.matchResult360 } else {361 this.env = {}362 }363 }364365 /**
430 unmodified lines