++perf --hack

This commit is contained in:
Mark Nadal 2018-02-13 13:36:54 -08:00
parent 20be1eba0d
commit 68587763f9
4 changed files with 22 additions and 27 deletions

31
gun.js
View File

@ -288,6 +288,7 @@
} }
}()); }());
Val.rel.ify = function(t){ return obj_put({}, rel_, t) } // convert a soul into a relation and return it. Val.rel.ify = function(t){ return obj_put({}, rel_, t) } // convert a soul into a relation and return it.
Type.obj.has._ = '.';
var rel_ = Val.rel._, u; var rel_ = Val.rel._, u;
var bi_is = Type.bi.is; var bi_is = Type.bi.is;
var num_is = Type.num.is; var num_is = Type.num.is;
@ -711,7 +712,10 @@
if(!Gun.graph.is(msg.put, null, verify, ctx)){ ctx.err = "Error: Invalid graph!" } if(!Gun.graph.is(msg.put, null, verify, ctx)){ ctx.err = "Error: Invalid graph!" }
if(ctx.err){ return at.on('in', {'@': msg['#'], err: Gun.log(ctx.err) }) } if(ctx.err){ return at.on('in', {'@': msg['#'], err: Gun.log(ctx.err) }) }
obj_map(ctx.put, merge, ctx); obj_map(ctx.put, merge, ctx);
if(!ctx.async){ obj_map(ctx.map, map, ctx) } if(!ctx.async){
at.stop = {}; // temporary fix till a better solution?
obj_map(ctx.map, map, ctx)
}
if(u !== ctx.defer){ if(u !== ctx.defer){
setTimeout(function(){ setTimeout(function(){
Gun.on.put(msg, gun); Gun.on.put(msg, gun);
@ -760,6 +764,7 @@
if(obj_map(ctx.souls, function(v){ if(v){ return v } })){ return } // if flag still outstanding, keep waiting. if(obj_map(ctx.souls, function(v){ if(v){ return v } })){ return } // if flag still outstanding, keep waiting.
if(ctx.c){ return } ctx.c = 1; // failsafe for only being called once per context. if(ctx.c){ return } ctx.c = 1; // failsafe for only being called once per context.
this.off(); this.off();
cat.stop = {}; // temporary fix till a better solution?
obj_map(ctx.map, map, ctx); // all done, trigger chains. obj_map(ctx.map, map, ctx); // all done, trigger chains.
}); });
} }
@ -778,10 +783,8 @@
} }
function map(msg, soul){ function map(msg, soul){
if(!msg.gun){ return } if(!msg.gun){ return }
msg.gun._.root._.stop = {};
//console.log('map ->', soul, msg.put); //console.log('map ->', soul, msg.put);
(msg.gun._).on('in', msg); (msg.gun._).on('in', msg);
msg.gun._.root._.stop = {};
} }
Gun.on.get = function(msg, gun){ Gun.on.get = function(msg, gun){
@ -944,9 +947,7 @@
//if(u !== back.put){ //if(u !== back.put){
back.on('in', back); back.on('in', back);
} }
if(back.ack){ if(back.ack){ return }
return;
}
msg.gun = back.gun; msg.gun = back.gun;
back.ack = -1; back.ack = -1;
} else } else
@ -1002,7 +1003,7 @@
} }
if(u === change){ if(u === change){
ev.to.next(msg); ev.to.next(msg);
if(cat.soul){ return } if(cat.soul){ return } // TODO: BUG, I believe the fresh input refactor caught an edge case that a `gun.get('soul').get('key')` that points to a soul that doesn't exist will not trigger val/get etc.
echo(cat, msg, ev); echo(cat, msg, ev);
if(cat.has){ if(cat.has){
not(cat, msg); not(cat, msg);
@ -1017,13 +1018,6 @@
obj_map(change, map, {at: msg, cat: cat}); obj_map(change, map, {at: msg, cat: cat});
return; return;
} }
/*if(rel = Gun.val.rel.is(change)){
if(tmp = (gun.back(-1).get(rel)._).put){
change = tmp; // this will cause performance to turn to mush, maybe use `.now` check?
}
//if(tmp.put){ change = tmp.put; }
}
if(!rel || tmp){*/
if(!(rel = Gun.val.rel.is(change))){ if(!(rel = Gun.val.rel.is(change))){
if(Gun.val.is(change)){ if(Gun.val.is(change)){
if(cat.has || cat.soul){ if(cat.has || cat.soul){
@ -1078,10 +1072,11 @@
// neither of these are ideal, need to be fixed without hacks, // neither of these are ideal, need to be fixed without hacks,
// but for now, this works for current tests. :/ // but for now, this works for current tests. :/
if(!now){ if(!now){
var stop = at.root._.stop; return;
/*var stop = at.root._.stop;
if(!stop){ return } if(!stop){ return }
if(stop[at.id] === rel){ return } if(stop[at.id] === rel){ return }
stop[at.id] = rel; stop[at.id] = rel;*/
} else { } else {
if(u === now[at.id]){ return } if(u === now[at.id]){ return }
if((now._ || (now._ = {}))[at.id] === rel){ return } if((now._ || (now._ = {}))[at.id] === rel){ return }
@ -1151,7 +1146,6 @@
function ask(at, soul){ function ask(at, soul){
var tmp = (at.root.get(soul)._); var tmp = (at.root.get(soul)._);
if(at.ack){ if(at.ack){
//tmp.ack = tmp.ack || -1;
tmp.on('out', {get: {'#': soul}}); tmp.on('out', {get: {'#': soul}});
if(!at.ask){ return } // TODO: PERFORMANCE? More elegant way? if(!at.ask){ return } // TODO: PERFORMANCE? More elegant way?
} }
@ -1371,13 +1365,14 @@
// and STOP is a hack to get async behavior to correctly call. // and STOP is a hack to get async behavior to correctly call.
// neither of these are ideal, need to be fixed without hacks, // neither of these are ideal, need to be fixed without hacks,
// but for now, this works for current tests. :/ // but for now, this works for current tests. :/
var tmp = cat.root._.now; obj.del(cat.root._, 'now'); var tmp = cat.root._.now; obj.del(cat.root._, 'now'); cat.root._.PUT = true;
var tmp2 = cat.root._.stop; var tmp2 = cat.root._.stop;
(as.ref._).now = true; (as.ref._).now = true;
(as.ref._).on('out', { (as.ref._).on('out', {
gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask
}); });
obj.del((as.ref._), 'now'); obj.del((as.ref._), 'now');
obj.del((cat.root._), 'PUT');
cat.root._.now = tmp; cat.root._.now = tmp;
cat.root._.stop = tmp2; cat.root._.stop = tmp2;
}, as); }, as);

View File

@ -1,6 +1,6 @@
{ {
"name": "gun", "name": "gun",
"version": "0.9.93", "version": "0.9.94",
"description": "A realtime, decentralized, offline-first, graph data synchronization engine.", "description": "A realtime, decentralized, offline-first, graph data synchronization engine.",
"main": "index.js", "main": "index.js",
"browser": "gun.min.js", "browser": "gun.min.js",

View File

@ -3753,18 +3753,18 @@ describe('Gun', function(){
}, 1); }, 1);
}); });
return;
it.only('get map should not slowdown', function(done){ it('get map should not slowdown', function(done){
this.timeout(5000); this.timeout(5000);
var gun = (window.gun = Gun()).get('g/m/no/slow'); var gun = Gun().get('g/m/no/slow');
//console.log("---------- setup data done -----------"); //console.log("---------- setup data done -----------");
var prev, diff, max = 25, total = 2, largest = -1, gone = {}; var prev, diff, max = 25, total = 9, largest = -1, gone = {};
//var prev, diff, max = Infinity, total = 10000, largest = -1, gone = {}; //var prev, diff, max = Infinity, total = 10000, largest = -1, gone = {};
// TODO: It would be nice if we could change these numbers for different platforms/versions of javascript interpreters so we can squeeze as much out of them. // TODO: It would be nice if we could change these numbers for different platforms/versions of javascript interpreters so we can squeeze as much out of them.
gun.get('history').map().on(function(time, index){ gun.get('history').map().on(function(time, index){
console.log(">>>", index, time); //console.log(">>>", index, time);
diff = Gun.time.is() - time; diff = Gun.time.is() - time;
return; //return;
expect(gone[index]).to.not.be.ok(); expect(gone[index]).to.not.be.ok();
gone[index] = diff; gone[index] = diff;
largest = (largest < diff)? diff : largest; largest = (largest < diff)? diff : largest;
@ -3783,8 +3783,8 @@ describe('Gun', function(){
prev = Gun.time.is(); prev = Gun.time.is();
var put = {}; put[turns += 1] = prev; var put = {}; put[turns += 1] = prev;
//console.log("put", put); //console.log("put", put);
console.log("------", turns, "-------"); //console.log("------", turns, "-------");
2 === turns && (console.debug.i = 1); //3 === turns && (console.debug.i = 1);
console.debug(1, 'save', {history: put}); console.debug(1, 'save', {history: put});
gun.put({history: put}); gun.put({history: put});
}, 1); }, 1);