Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[geometry-1] Steps for multiplySelf are inefficient #580

Open
trusktr opened this issue Dec 27, 2024 · 0 comments
Open

[geometry-1] Steps for multiplySelf are inefficient #580

trusktr opened this issue Dec 27, 2024 · 0 comments

Comments

@trusktr
Copy link

trusktr commented Dec 27, 2024

The steps for multiplySelf are:

  1. Let otherObject be the result of invoking create a DOMMatrix from the dictionary other.
  2. The otherObject matrix gets post-multiplied to the current matrix.
  3. If 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:

	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 getter, and DOMMatrix adds the setter 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant