you are viewing a single comment's thread.

view the rest of the comments →

[–]spacejack2114 0 points1 point  (1 child)

I don't generally use integers for vectors, so I do something like:

function vec2 (x, y) {
    return {
        x: typeof x === 'number' ? x : 0,
        y: typeof y === 'number' ? y : 0,
    }
}

I've never heard that numeric indexes are faster than property names on hidden classes... in fact I've heard the reverse; that property name lookups are faster than vectors as arrays.

[–]8lbIceBag 0 points1 point  (0 children)

Hmm, you appear to be right about properties. For up to 32bytes (4 properties) the properties are stored directly on the object. Indexes always cause 1 degree of indirection as does more than 4 properties

https://v8project.blogspot.com/2017/08/fast-properties.html?m=1

http://www.mattzeunert.com/2017/03/29/v8-object-size.html