diff --git a/packages/@glimmer/validator/lib/tracked-value.ts b/packages/@glimmer/validator/lib/tracked-value.ts index b08c964c6c7..c3885187380 100644 --- a/packages/@glimmer/validator/lib/tracked-value.ts +++ b/packages/@glimmer/validator/lib/tracked-value.ts @@ -29,6 +29,19 @@ export class TrackedValue implements Reactive { readonly #tag: UpdatableTag; constructor(value: Value, options: ReactiveOptions) { + /** + * If we let V8 try to completely optimize TrackedValue for + * for each type of `value`, + * that performs worse than making V8 only use one internal + * internal version of the class for each type of `value`. + * + * The first value of another kind makes V8 throw away + * the optimized code that reads the field. + * + * The field starts as `undefined`, + * so a number here makes it general from the first instance. + */ + this.#value = 0 as Value; this.#value = value; this.#options = options; this.#tag = createUpdatableTag();