performance

Installation
SKILL.md

Closure→class refactor for hot dispatch sites

The problem in 30 seconds

A factory shaped like this:

function createColumn(array) {
  return {
    get(i)    { return array[i]; },
    set(i, v) { array[i] = v; },
  };
}

…creates a fresh hidden class plus fresh per-instance methods every call. When a tight loop sees several such instances at the same call site (positionX.get(i), positionY.get(i), velocityX.get(i), …), V8's inline cache goes polymorphic → megamorphic and the methods can't be inlined. Each .get call dereferences the closure context to read array. Same data flow, but the loop is 5× slower than it needs to be.

Replace with a class — class Column { array; constructor(a) { this.array = a; } get(i) { return this.array[i]; } } — and every instance shares one hidden class and one set of prototype methods. The IC monomorphizes, V8 inlines .get, and array becomes a fast property load.

Installs
1
Repository
adobe/data
GitHub Stars
10
First Seen
Jun 16, 2026
performance — adobe/data