[fxtf-drafts] [geometry-1] Steps for `multiplySelf` are inefficient (#580)

trusktr has just created a new issue for https://github.com/w3c/fxtf-drafts:

== [geometry-1] Steps for `multiplySelf` are inefficient ==
The steps for [multiplySelf](https://drafts.fxtf.org/geometry/#dom-dommatrix-multiplyself) are:

1. Let otherObject be the result of invoking [create a DOMMatrix from the dictionary](https://drafts.fxtf.org/geometry/#create-a-dommatrix-from-the-dictionary) other.
2. The otherObject matrix gets post-multiplied to the current matrix.
3. If [is 2D](https://drafts.fxtf.org/geometry/#matrix-is-2d) of otherObject is false, set is 2D of the current matrix to false.
4. Return the current matrix.

This means that for step 1, if we pass in a DOMMatrix (which is assignable to DOMMatrixInit), we will create a new DOMMatrix from the passed-in DOMMatrix, which is unnecessary overhead.

In practice, that means something like the following for the implementation:

```ts
 multiplySelf(other: DOMMatrixInit) {
  const otherMat = new DOMMatrix([other.m11, other.m12, ..., other.m44])

  // ... perform the multiplication ...

  if (!otherMat[is2D]) this[is2D] = false

  return this
 }
```

(where `is2D` is a `symbol` that I use for the "priate" `is2D` state in JavaScript (`DOMMatrixReadOnly` returns the value from a readonly `get`ter, and `DOMMatrix` adds the `set`ter for it).

As you can see here, creating a `new DOMMatrix` every time we want to multiply is wasteful, and for every frame of an animation this will create a new object that needs to be garbage collected.

Can we change the spec to specify that a new DOMMatrix does not need to be constructed if a DOMMatrix is passed in?

Please view or discuss this issue at https://github.com/w3c/fxtf-drafts/issues/580 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 27 December 2024 08:43:02 UTC