Fixed performance regression in dependency graph speed

This commit is contained in:
ThaumRystra
2023-09-22 16:45:40 +02:00
parent 572078c2fa
commit bfbb31d30c
2 changed files with 14 additions and 7 deletions

View File

@@ -9,8 +9,15 @@ export default function linkCalculationDependencies(dependencyGraph, prop, { pro
};
// Add this calculation to the dependency graph
const calcNodeId = `${prop._id}.${calcObj._key}`;
dependencyGraph.addNode(calcNodeId, calcObj);
// Skip empty calculations that aren't targeted by anything
if (
!calcObj.calculation
&& !calcObj.effects
&& !calcObj.proficiencies
) return;
dependencyGraph.addNode(calcNodeId, calcObj);
// Traverse the parsed calculation looking for variable names
traverse(calcObj.parseNode, node => {
// Skip nodes that aren't symbols or accessors

View File

@@ -98,8 +98,10 @@ function linkAdjustment(dependencyGraph, prop) {
function linkAttribute(dependencyGraph, prop) {
linkVariableName(dependencyGraph, prop);
// Depends on spellSlotLevel
dependOnCalc({ dependencyGraph, prop, key: 'spellSlotLevel' });
// Spell slots depend on spellSlotLevel
if (prop.type === 'spellSlot') {
dependOnCalc({ dependencyGraph, prop, key: 'spellSlotLevel' });
}
// Depends on base value
dependOnCalc({ dependencyGraph, prop, key: 'baseValue' });
@@ -257,8 +259,8 @@ function linkDamageMultiplier(dependencyGraph, prop) {
function linkPointBuy(dependencyGraph, prop) {
dependOnCalc({ dependencyGraph, prop, key: 'min' });
dependOnCalc({ dependencyGraph, prop, key: 'max' });
dependOnCalc({ dependencyGraph, prop, key: 'cost' });
dependOnCalc({ dependencyGraph, prop, key: 'total' });
prop.values?.forEach((row, index) => {
// Get a unique id for the row because it might be shared among duplicated point buy tables
// prop._id is forced unique by the database, so it can be used instead
@@ -273,9 +275,7 @@ function linkPointBuy(dependencyGraph, prop) {
}
dependencyGraph.addNode(pointBuyRow._id, pointBuyRow);
linkVariableName(dependencyGraph, pointBuyRow);
dependOnCalc({ dependencyGraph, pointBuyRow, key: 'min' });
dependOnCalc({ dependencyGraph, pointBuyRow, key: 'max' });
dependOnCalc({ dependencyGraph, pointBuyRow, key: 'cost' });
dependencyGraph.addLink(pointBuyRow._id, prop._id, 'pointBuyRow');
});
if (prop.inactive) return;
}