Files
DiceCloud/app/imports/api/engine/computation/CreatureComputation.js
Stefan Zermatten cb1fd38df3 Optimized some slow parts of the engine.
Last low hanging fruit: parsing is slow, cache parsed calculations
2021-09-29 15:54:14 +02:00

26 lines
762 B
JavaScript

import { EJSON } from 'meteor/ejson';
import createGraph from 'ngraph.graph';
export default class CreatureComputation {
constructor(properties){
// Set up fields
this.originalPropsById = {};
this.propsById = {};
this.scope = {};
this.props = properties;
this.dependencyGraph = createGraph();
// Store properties for easy access later
properties.forEach(prop => {
// Store a copy of the unmodified prop
// EJSON clone is ~4x faster than lodash cloneDeep for EJSONable objects
this.originalPropsById[prop._id] = EJSON.clone(prop);
// Store by id
this.propsById[prop._id] = prop;
// Store the prop in the dependency graph
this.dependencyGraph.addNode(prop._id, prop);
});
}
}