From b76e9ad795a62ed003b1f937e23fcac74393fa8a Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 5 Oct 2026 22:18:52 -0400 Subject: [PATCH 1/2] Make the value field of a TrackedValue general from the first instance All instances have one hidden class, and V8 records which kind of value the `#value` field held so far. If no instance held a number yet, the first number makes V8 throw away the optimized code of each function that reads a TrackedValue. The constructor now stores a number before the value, so the field is general from the first instance. Split out of #21650. Co-Authored-By: Claude Opus 5.5 (1M context) --- packages/@glimmer/validator/lib/tracked-value.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/@glimmer/validator/lib/tracked-value.ts b/packages/@glimmer/validator/lib/tracked-value.ts index b08c964c6c7..52e2124e7e0 100644 --- a/packages/@glimmer/validator/lib/tracked-value.ts +++ b/packages/@glimmer/validator/lib/tracked-value.ts @@ -29,6 +29,17 @@ export class TrackedValue implements Reactive { readonly #tag: UpdatableTag; constructor(value: Value, options: ReactiveOptions) { + /** + * All instances have one hidden class, + * and V8 records which kind of value `#value` held so far. + * + * 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(); From 0080d2dd8c20ffa841a5698922b84efac8d67546 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:34:43 -0400 Subject: [PATCH 2/2] Refactor comments in tracked-value.ts constructor Updated comments in the constructor for clarity. Linting --- packages/@glimmer/validator/lib/tracked-value.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/@glimmer/validator/lib/tracked-value.ts b/packages/@glimmer/validator/lib/tracked-value.ts index 52e2124e7e0..c3885187380 100644 --- a/packages/@glimmer/validator/lib/tracked-value.ts +++ b/packages/@glimmer/validator/lib/tracked-value.ts @@ -30,14 +30,16 @@ export class TrackedValue implements Reactive { constructor(value: Value, options: ReactiveOptions) { /** - * All instances have one hidden class, - * and V8 records which kind of value `#value` held so far. + * 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 optimized code that reads the field. * * The field starts as `undefined`, - * so a number here makes it general from the first instance. + * so a number here makes it general from the first instance. */ this.#value = 0 as Value; this.#value = value;