Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- perf(ObjectGeometry): replace cache key string with array [#9887](https://github.com/fabricjs/fabric.js/pull/9887)
- fix(util): restore old composeMatrix code for performances improvement [#9851](https://github.com/fabricjs/fabric.js/pull/9851)
- fix(Control): corner coords definition order [#9884](https://github.com/fabricjs/fabric.js/pull/9884)
- fix(Polyline): safeguard points arg from options [#9855](https://github.com/fabricjs/fabric.js/pull/9855)
Expand Down
56 changes: 23 additions & 33 deletions src/shapes/Object/ObjectGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import type { StaticCanvas } from '../../canvas/StaticCanvas';
import { ObjectOrigin } from './ObjectOrigin';
import type { ObjectEvents } from '../../EventTypeDefs';
import type { ControlProps } from './types/ControlProps';
import { resolveOrigin } from '../../util/misc/resolveOrigin';

type TMatrixCache = {
key: string;
key: number[];
value: TMat2D;
};

Expand Down Expand Up @@ -437,40 +438,29 @@ export class ObjectGeometry<EventSpec extends ObjectEvents = ObjectEvents>
this.aCoords = this.calcACoords();
}

transformMatrixKey(skipGroup = false): string {
const sep = '_';
let prefix = '';
transformMatrixKey(skipGroup = false): number[] {
let prefix: number[] = [];
if (!skipGroup && this.group) {
prefix = this.group.transformMatrixKey(skipGroup) + sep;
prefix = this.group.transformMatrixKey(skipGroup);
}
return (
prefix +
this.top +
sep +
this.left +
sep +
this.scaleX +
sep +
this.scaleY +
sep +
this.skewX +
sep +
this.skewY +
sep +
this.angle +
sep +
this.originX +
sep +
this.originY +
sep +
this.width +
sep +
this.height +
sep +
this.strokeWidth +
this.flipX +
this.flipY
prefix.push(
this.top,
this.left,
this.scaleX,
this.scaleY,
this.skewX,
this.skewY,
this.angle,
resolveOrigin(this.originX),
resolveOrigin(this.originY),
this.width,
this.height,
+this.flipX,
+this.flipY,
this.strokeWidth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would argue that angle could go right away top and left, then width, height, scaleX and scaleY and then all the rest. Origin last. Is probably non influent but i would have the properties that have a chance to change more often at the top of the array.

I also think this list could be flawed for the exactbounding box case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I've sorted properties by likelihook of change. I put angle after scale as I think it's less probable. People usually move, resize, scale objects and then less frequently rotate them.

An advantage of this method is also that it's easy to override in the app and sort/remove the properties according to the app.

I also think this list could be flawed for the exactbounding box case

Not sure to understand what you're referring and what would be the action

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant that when exactBoudning box is in play all the stroke join properties influence position and so the matrix.
That could be source of super hidden bugs that we think are calculation issues and maybe are not. But this is a pre-existing bug ad has nothing to do with this PR

);

return prefix;
}

/**
Expand All @@ -487,7 +477,7 @@ export class ObjectGeometry<EventSpec extends ObjectEvents = ObjectEvents>
}
const key = this.transformMatrixKey(skipGroup),
cache = this.matrixCache;
if (cache && cache.key === key) {
if (cache && cache.key.every((x, i) => x === key[i])) {
return cache.value;
}
if (this.group) {
Expand Down