perf notes

This commit is contained in:
Mark Nadal 2020-03-02 13:14:04 -08:00
parent 6f053b6327
commit 3733473115
6 changed files with 17 additions and 6 deletions

11
gun.js
View File

@ -2094,7 +2094,7 @@
root.on('in', msg);
//ECHO = msg.put || ECHO; !(msg.ok !== -3740) && mesh.say({ok: -3740, put: ECHO, '@': msg['#']}, peer);
DBG && (DBG.hd = +new Date);
console.STAT && (ST = +new Date - S) > 9 && console.STAT(S, ST, 'msg');
console.STAT && (ST = +new Date - S) > 9 && console.STAT(S, ST, 'msg'); // TODO: PERF: caught one > 1.5s on tgif
dup_track(id).via = peer;
mesh.leap = null; // warning! mesh.leap could be buggy.
}
@ -2138,8 +2138,10 @@
if(!peer || !peer.id){ message = msg;
if(!Type.obj.is(peer || opt.peers)){ return false }
var S = +new Date;
var wr = meta.raw; meta.raw = raw; // quick perf hack
Type.obj.map(peer || opt.peers, each); // in case peer is a peer list.
console.STAT && console.STAT(S, +new Date - S, 'say loop');
meta.raw = wr;
console.STAT && console.STAT(S, +new Date - S, 'say loop'); // PERF: TODO: 1.4s+ on tgif, NEED PUFF
return;
}
if(!peer.wire && mesh.wire){ mesh.wire(peer) }
@ -2210,6 +2212,10 @@
raw = raw.slice(0, tmp-1) + put + raw.slice(tmp + _.length + 1);
//raw = raw.replace('"'+ _ +'"', put); // NEVER USE THIS! ALSO NEVER DELETE IT TO NOT MAKE SAME MISTAKE! https://github.com/amark/gun/wiki/@$$ Heisenbug
}*/
// TODO: PERF: tgif, CPU way too much on re-JSONifying ^ it.
/*
// NOTE TO SELF: Switch NTS to DAM now.
*/
if(meta && (raw||'').length < (1000 * 100)){ meta.raw = raw } // HNPERF: If string too big, don't keep in memory.
return raw;
}
@ -2270,6 +2276,7 @@
setTimeout(function(){ delete gets[tmp] },opt.lack || 9000);
});
root.on('hi', function(peer, tmp){ this.to.next(peer);
// TODO: PERF: these things are too slow. Probably `root.next` loop? Huh? is it discovering itself? What going on.
if(!(tmp = peer.url) || !gets[tmp]){ return } delete gets[tmp];
Type.obj.map(root.next, function(node, soul){
tmp = {}; tmp[soul] = root.graph[soul];

View File

@ -34,8 +34,9 @@ function serve(req, res, next){ var tmp;
}
var S = +new Date;
var rs = fs.createReadStream(path);
rs.on('open', function(){ console.STAT && console.STAT(S, +new Date - S, 'serve open file'); rs.pipe(res) });
rs.on('open', function(){ rs.pipe(res) });
rs.on('error', function(err){ res.end(404+'') });
rs.on('end', function(){ console.STAT && console.STAT(S, +new Date - S, 'serve file end') });
return true;
}
if((tmp = req.socket) && (tmp = tmp.server) && (tmp = tmp.route)){ var url;

View File

@ -2,7 +2,7 @@
var Gun = require('../gun'), u;
Gun.serve = require('./serve');
//process.env.GUN_ENV = process.env.GUN_ENV || 'debug';
console.LOG = {}; // only do this for dev.
//console.LOG = {}; // only do this for dev.
Gun.on('opt', function(root){
if(u === root.opt.super){ root.opt.super = true }
if(u === root.opt.faith){ root.opt.faith = true } // HNPERF: This should probably be off, but we're testing performance improvements, please audit.

View File

@ -72,5 +72,6 @@ Gun.log = console.STAT = function(a,b,c,d){
if(max < tmp.push([a,b])){ all[c] = [] } // reset
//return;
}
if(!console.LOG || log.off){ return }
return log.apply(Gun, arguments);
}

View File

@ -78,7 +78,7 @@ Gun.on('opt', function(root){
opt.mesh.bye(peer);
});
wire.on('error', function(e){});
setTimeout(function heart(){ if(!opt.peers[peer.id]){ return } try{ wire.send("[]"); setTimeout(heart, 1000 * 20) }catch(e){} }, 1000 * 20); // Some systems, like Heroku, require heartbeats to not time out. // TODO: Make this configurable?
setTimeout(function heart(){ if(!opt.peers[peer.id]){ return } try{ wire.send("[]") }catch(e){} ;setTimeout(heart, 1000 * 20) }, 1000 * 20); // Some systems, like Heroku, require heartbeats to not time out. // TODO: Make this configurable? // TODO: PERF: Find better approach than try/timeouts?
});
}

View File

@ -56,11 +56,13 @@
},
"dependencies": {
"buffer": "^5.4.3",
"ws": "^7.1.2"
"ws": "^7.2.1"
},
"optionalDependencies": {
"text-encoding": "^0.7.0",
"isomorphic-webcrypto": "^2.3.2",
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2",
"emailjs": "^2.2.0"
},
"devDependencies": {