From 68587763f9426c82ef38814d22fa294f14d6e5a0 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 13 Feb 2018 13:36:54 -0800 Subject: [PATCH] ++perf --hack --- gun.js | 31 +++++++++++++------------------ untitled.js => lib/untitled.js | 0 package.json | 2 +- test/common.js | 16 ++++++++-------- 4 files changed, 22 insertions(+), 27 deletions(-) rename untitled.js => lib/untitled.js (100%) diff --git a/gun.js b/gun.js index 94c3f5aa..8c49d684 100644 --- a/gun.js +++ b/gun.js @@ -288,6 +288,7 @@ } }()); 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 bi_is = Type.bi.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(ctx.err){ return at.on('in', {'@': msg['#'], err: Gun.log(ctx.err) }) } 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){ setTimeout(function(){ 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(ctx.c){ return } ctx.c = 1; // failsafe for only being called once per context. this.off(); + cat.stop = {}; // temporary fix till a better solution? obj_map(ctx.map, map, ctx); // all done, trigger chains. }); } @@ -778,10 +783,8 @@ } function map(msg, soul){ if(!msg.gun){ return } - msg.gun._.root._.stop = {}; //console.log('map ->', soul, msg.put); (msg.gun._).on('in', msg); - msg.gun._.root._.stop = {}; } Gun.on.get = function(msg, gun){ @@ -944,9 +947,7 @@ //if(u !== back.put){ back.on('in', back); } - if(back.ack){ - return; - } + if(back.ack){ return } msg.gun = back.gun; back.ack = -1; } else @@ -1002,7 +1003,7 @@ } if(u === change){ 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); if(cat.has){ not(cat, msg); @@ -1017,13 +1018,6 @@ obj_map(change, map, {at: msg, cat: cat}); 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(Gun.val.is(change)){ if(cat.has || cat.soul){ @@ -1078,10 +1072,11 @@ // neither of these are ideal, need to be fixed without hacks, // but for now, this works for current tests. :/ if(!now){ - var stop = at.root._.stop; + return; + /*var stop = at.root._.stop; if(!stop){ return } if(stop[at.id] === rel){ return } - stop[at.id] = rel; + stop[at.id] = rel;*/ } else { if(u === now[at.id]){ return } if((now._ || (now._ = {}))[at.id] === rel){ return } @@ -1151,7 +1146,6 @@ function ask(at, soul){ var tmp = (at.root.get(soul)._); if(at.ack){ - //tmp.ack = tmp.ack || -1; tmp.on('out', {get: {'#': soul}}); 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. // neither of these are ideal, need to be fixed without hacks, // 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; (as.ref._).now = true; (as.ref._).on('out', { gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask }); obj.del((as.ref._), 'now'); + obj.del((cat.root._), 'PUT'); cat.root._.now = tmp; cat.root._.stop = tmp2; }, as); diff --git a/untitled.js b/lib/untitled.js similarity index 100% rename from untitled.js rename to lib/untitled.js diff --git a/package.json b/package.json index e9add17c..6372fd2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.9.93", + "version": "0.9.94", "description": "A realtime, decentralized, offline-first, graph data synchronization engine.", "main": "index.js", "browser": "gun.min.js", diff --git a/test/common.js b/test/common.js index 73e93438..72345f97 100644 --- a/test/common.js +++ b/test/common.js @@ -3753,18 +3753,18 @@ describe('Gun', function(){ }, 1); }); - return; - it.only('get map should not slowdown', function(done){ + + it('get map should not slowdown', function(done){ 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 -----------"); - 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 = {}; // 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){ - console.log(">>>", index, time); + //console.log(">>>", index, time); diff = Gun.time.is() - time; - return; + //return; expect(gone[index]).to.not.be.ok(); gone[index] = diff; largest = (largest < diff)? diff : largest; @@ -3783,8 +3783,8 @@ describe('Gun', function(){ prev = Gun.time.is(); var put = {}; put[turns += 1] = prev; //console.log("put", put); - console.log("------", turns, "-------"); - 2 === turns && (console.debug.i = 1); + //console.log("------", turns, "-------"); + //3 === turns && (console.debug.i = 1); console.debug(1, 'save', {history: put}); gun.put({history: put}); }, 1);