Upload
roman-krivtsov
View
998
Download
0
Embed Size (px)
Citation preview
Leaks in js:Easy to create (timers, closures, listeners)
Difficult to find out
Critical in long-live apps
—
—
—
2
— Concept of reachability— Blocked event-loop— Totally optimising
(partions, dynamic intervals)— New space (1-8Mb)
& Old space (512Mb-1.7Gb)
6
GC
— max-old-space-size limit for old-space GC
— nouse-idle-notification prevent running GC constantly
— expose-gc global.gc()
— trace-gc logging
— trace-gc-verbose extended logging
Flags
7
var latestNews = function (html) { var container = document.getElementById("news"); container.innerHTML = html; container.addEventListener("click", function click() { showFullItem(); }); } setInterval(XHR.bind(null, "/get_news", latestNews), 1000);
9
Latest news
12
var latestNews = function (html) { var container = document.getElementById("news"); container.innerHTML = html; container.addEventListener("click", function click() { showFullItem(html); }); } setInterval(XHR.bind(null, "/get_news", latestNews), 1000);
Variable usage
15
var latestNews = function (html) { var container = document.getElementById("news"); container.innerHTML = html; container.addEventListener("click", function click() { showFullItem(); });
var unused = function () { if (html) console.log("never"); }} setInterval(XHR.bind(null, "/get_news", latestNews), 1000);
Deeper down the rabbit hole
18
var latestNews = function (html) { var container = document.getElementById("news"); container.innerHTML = html; html = null; container.addEventListener("click", function click() { showFullItem(html); }); } setInterval(XHR.bind(null, "/get_news", latestNews), 1000);
var job = function () { mysql.query("select * from tasks order by ts desc", function (err, res) { use(res); }); } setInterval(job, 1000);
19
Long responses
mysql.query({ sql: 'select * from tasks order by ts', timeout: 1000});
— Timers— Frequent events— Listeners— Parent scope— Give names— Clear big variables— Databases
Conclusions
25