faster state

This commit is contained in:
Mark Nadal 2017-03-23 11:40:46 -07:00
parent b085d7a197
commit e0153db653
4 changed files with 16 additions and 5 deletions

8
gun.js
View File

@ -542,13 +542,19 @@
var Type = require('./type');
var Node = require('./node');
function State(){
var t = time();
var t;
if(perf){
t = start + perf.now();
} else {
t = time();
}
if(last < t){
return N = 0, last = t;
}
return last = t + ((N += 1) / D);
}
var time = Type.time.is, last = -Infinity, N = 0, D = 1000; // WARNING! In the future, on machines that are D times faster than 2016AD machines, you will want to increase D by another several orders of magnitude so the processing speed never out paces the decimal resolution (increasing an integer effects the state accuracy).
var perf = (typeof performance !== 'undefined')? (performance.timing && performance) : false, start = (perf && perf.timing && perf.timing.navigationStart) || (perf = false);
State._ = '>';
State.ify = function(n, f, s, v, soul){ // put a field's state on a node.
if(!n || !n[N_]){ // reject if it is not node-like.

2
gun.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,8 @@
var Gun = require('./root');
Gun.chain.get = function(key, cb, as){
//if(!as || !as.path){ var back = this._.root; } // TODO: CHANGING API! Remove this line!
if(typeof key === 'string'){
var gun, back = back || this, cat = back._;
var gun, back = this, cat = back._;
var next = cat.next || empty, tmp;
if(!(gun = next[key])){
gun = cache(key, back);

View File

@ -2,13 +2,19 @@
var Type = require('./type');
var Node = require('./node');
function State(){
var t = time();
var t;
if(perf){
t = start + perf.now();
} else {
t = time();
}
if(last < t){
return N = 0, last = t;
}
return last = t + ((N += 1) / D);
}
var time = Type.time.is, last = -Infinity, N = 0, D = 1000; // WARNING! In the future, on machines that are D times faster than 2016AD machines, you will want to increase D by another several orders of magnitude so the processing speed never out paces the decimal resolution (increasing an integer effects the state accuracy).
var perf = (typeof performance !== 'undefined')? (performance.timing && performance) : false, start = (perf && perf.timing && perf.timing.navigationStart) || (perf = false);
State._ = '>';
State.ify = function(n, f, s, v, soul){ // put a field's state on a node.
if(!n || !n[N_]){ // reject if it is not node-like.