From 93f1480af39c1eadf130c069f95416be55a0a970 Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Fri, 14 Aug 2015 11:33:12 +0200 Subject: [PATCH] - improved performance --- dist/vis.js | 14 +++++++++----- lib/network/modules/PhysicsEngine.js | 15 +++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dist/vis.js b/dist/vis.js index e3761ba1..900e65c5 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -33019,6 +33019,7 @@ return /******/ (function(modules) { // webpackBootstrap this.previousStates = {}; this.referenceState = {}; this.adaptiveTimestep = true; + this.adaptiveTimestepEnabled = false; this.adaptiveCounter = 0; this.adaptiveInterval = 2; this.freezeCache = {}; @@ -33297,11 +33298,11 @@ return /******/ (function(modules) { // webpackBootstrap value: function physicsTick() { if (this.stabilized === false) { // adaptivity means the timestep adapts to the situation, only applicable for stabilization - if (this.adaptiveTimestep === true) { + if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) { this.adaptiveCounter += 1; + var factor = 1.2; if (this.adaptiveCounter % this.adaptiveInterval === 0) { // we leave the timestep stable for "interval" iterations. - //console.log(this.timestep) // first the big step and revert. Revert saves the reference state. this.timestep = 2 * this.timestep; this.calculateForces(); @@ -33319,18 +33320,18 @@ return /******/ (function(modules) { // webpackBootstrap // we compare the two steps. if it is acceptable we double the step. if (this.compare() === true) { - this.timestep = 1.1 * this.timestep; + this.timestep = factor * this.timestep; } else { // if not, we half the step to a minimum of the options timestep. // if the half the timestep is smaller than the options step, we do not reset the counter // we assume that the options timestep is stable enough. - if (0.9 * this.timestep < this.options.timestep) { + if (this.timestep / factor < this.options.timestep) { this.timestep = this.options.timestep; } else { // if the timestep was larger than 2 times the option one we check the adaptivity again to ensure // that large instabilities do not form. this.adaptiveCounter = -1; // check again next iteration - this.timestep = 0.9 * this.timestep; + this.timestep = Math.max(this.options.timestep, this.timestep / factor); } } } else { @@ -33478,6 +33479,7 @@ return /******/ (function(modules) { // webpackBootstrap var nodeIndices = this.physicsBody.physicsNodeIndices; var maxVelocity = this.options.maxVelocity ? this.options.maxVelocity : 1e9; var maxNodeVelocity = 0; + var velocityAdaptiveThreshold = 5; for (var i = 0; i < nodeIndices.length; i++) { var nodeId = nodeIndices[i]; @@ -33487,6 +33489,8 @@ return /******/ (function(modules) { // webpackBootstrap nodesPresent = true; } + this.adaptiveTimestepEnabled = maxNodeVelocity < velocityAdaptiveThreshold; + this.stabilized = maxNodeVelocity <= this.options.minVelocity; } diff --git a/lib/network/modules/PhysicsEngine.js b/lib/network/modules/PhysicsEngine.js index a447b79b..c136352b 100644 --- a/lib/network/modules/PhysicsEngine.js +++ b/lib/network/modules/PhysicsEngine.js @@ -21,6 +21,7 @@ class PhysicsEngine { this.previousStates = {}; this.referenceState = {}; this.adaptiveTimestep = true; + this.adaptiveTimestepEnabled = false; this.adaptiveCounter = 0; this.adaptiveInterval = 2; this.freezeCache = {}; @@ -279,10 +280,10 @@ class PhysicsEngine { physicsTick() { if (this.stabilized === false) { // adaptivity means the timestep adapts to the situation, only applicable for stabilization - if (this.adaptiveTimestep === true) { + if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) { this.adaptiveCounter += 1; + let factor = 1.2; if (this.adaptiveCounter % this.adaptiveInterval === 0) { // we leave the timestep stable for "interval" iterations. - //console.log(this.timestep) // first the big step and revert. Revert saves the reference state. this.timestep = 2 * this.timestep; this.calculateForces(); @@ -300,20 +301,20 @@ class PhysicsEngine { // we compare the two steps. if it is acceptable we double the step. if (this.compare() === true) { - this.timestep = 1.1 * this.timestep; + this.timestep = factor * this.timestep; } else { // if not, we half the step to a minimum of the options timestep. // if the half the timestep is smaller than the options step, we do not reset the counter // we assume that the options timestep is stable enough. - if (0.9 * this.timestep < this.options.timestep) { + if (this.timestep/factor < this.options.timestep) { this.timestep = this.options.timestep; } else { // if the timestep was larger than 2 times the option one we check the adaptivity again to ensure // that large instabilities do not form. this.adaptiveCounter = -1; // check again next iteration - this.timestep = 0.9 * this.timestep; + this.timestep = Math.max(this.options.timestep, this.timestep/factor); } } } @@ -456,7 +457,7 @@ class PhysicsEngine { var nodeIndices = this.physicsBody.physicsNodeIndices; var maxVelocity = this.options.maxVelocity ? this.options.maxVelocity : 1e9; var maxNodeVelocity = 0; - + var velocityAdaptiveThreshold = 5; for (let i = 0; i < nodeIndices.length; i++) { let nodeId = nodeIndices[i]; @@ -466,6 +467,8 @@ class PhysicsEngine { nodesPresent = true; } + this.adaptiveTimestepEnabled = maxNodeVelocity < velocityAdaptiveThreshold; + this.stabilized = maxNodeVelocity <= this.options.minVelocity; }