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

Improve performance by avoiding repeated recalculateRenderedStyle #3309 #3310

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from
Open
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
15 changes: 2 additions & 13 deletions src/collection/dimensions/bounds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as is from '../../is';
import { assignBoundingBox, expandBoundingBoxSides, clearBoundingBox, expandBoundingBox, makeBoundingBox, copyBoundingBox, shiftBoundingBox, updateBoundingBox } from '../../math';
import { defaults, getPrefixedProperty, hashIntsArray } from '../../util';
import { defaults, getPrefixedProperty, getBoundingBoxPosKey } from '../../util';

let fn, elesfn;

Expand Down Expand Up @@ -800,18 +800,6 @@ let getKey = function( opts ){
return key;
};

let getBoundingBoxPosKey = ele => {
if( ele.isEdge() ){
let p1 = ele.source().position();
let p2 = ele.target().position();
let r = x => Math.round(x);

return hashIntsArray([ r(p1.x), r(p1.y), r(p2.x), r(p2.y) ]);
} else {
return 0;
}
};

let cachedBoundingBoxImpl = function( ele, opts ){
let _p = ele._private;
let bb;
Expand Down Expand Up @@ -926,6 +914,7 @@ elesfn.boundingBox = function( options ){
let isPosKeySame = _p.bbCachePosKey === currPosKey;
let useCache = opts.useCache && isPosKeySame && !_p.styleDirty;

_p.bbCachePosKey = currPosKey;
ele.recalculateRenderedStyle( useCache );
}
}
Expand Down
25 changes: 2 additions & 23 deletions src/extensions/renderer/base/coord-ele-math/edge-control-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,28 +706,7 @@ BRp.findEdgeControlPoints = function( edges ){
let cy = r.cy;
let hasCompounds = cy.hasCompoundNodes();

let hashTable = {
map: new Map(),
get: function(pairId){
let map2 = this.map.get(pairId[0]);

if( map2 != null ){
return map2.get(pairId[1]);
} else {
return null;
}
},
set: function(pairId, val){
let map2 = this.map.get(pairId[0]);

if( map2 == null ){
map2 = new Map();
this.map.set(pairId[0], map2);
}

map2.set(pairId[1], val);
}
};
let hashTable = new Map();

let pairIds = [];
let haystackEdges = [];
Expand Down Expand Up @@ -756,7 +735,7 @@ BRp.findEdgeControlPoints = function( edges ){
let srcIndex = src.poolIndex();
let tgtIndex = tgt.poolIndex();

let pairId = [ srcIndex, tgtIndex ].sort();
let pairId = `${srcIndex}_${tgtIndex}_${edgeIsUnbundled}`;
Copy link
Member

Choose a reason for hiding this comment

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

This needs to have the IDs sorted, because a bezier bundle can contain edges that go in either direction, e.g.

E1: A -> B
and
E2: B ->A
could both be in the same bundle


let tableEntry = hashTable.get( pairId );

Expand Down
4 changes: 4 additions & 0 deletions src/extensions/renderer/base/coord-ele-math/rendered-style.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getBoundingBoxPosKey } from '../../../../util';

let BRp = {};

BRp.registerCalculationListeners = function(){
Expand Down Expand Up @@ -50,6 +52,8 @@ BRp.registerCalculationListeners = function(){
enqueue( ele.connectedEdges() );

rstyle.cleanConnected = true;
} else if (ele.isEdge()) {
ele._private.bbCachePosKey = getBoundingBoxPosKey( ele );
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/util/bounds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { hashIntsArray } from '.';

export const getBoundingBoxPosKey = (ele) => {
if (ele.isEdge()) {
let p1 = ele.source().position();
let p2 = ele.target().position();
let r = (x) => Math.round(x);

return hashIntsArray([r(p1.x), r(p1.y), r(p2.x), r(p2.y)]);
} else {
return 0;
}
};
1 change: 1 addition & 0 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './maps';
export * from './strings';
export * from './timing';
export * from './hash';
export * from './bounds';

export { strings, extend, extend as assign, memoize, regex, sort };

Expand Down