Improve Application Performance
object [ key ] = value ;
String only
Any variable type
The Object itself
Usually a small constant footprint
The sum of shallow size of all decendents
Find all garbage
Return memory used by garbage variables to the system
Scoops memory from the "young" memory pool
This is cheap & fast until this pool runs out of memory
Mind new objects creation patterns
Mind how long you hold on to them
Allocations are cheap & fast until
the "young" pool runs out of memory
Shallow (self)
Retained (self+descendents)
Runtime is then forced to perform a garbage collection
which can lead to clunky performance...
Free during development for debugging
License is required to run in production
Free open source PM2 package
License is required for dashboards
by Rising stack
Has a free tier
Available as built-in or 3rd-party middleware
Watch this for further information
Runtime Performance Workflow
All tabs available including: Sources / Timeline / Profiling
A debugger interface for Node.js applications
uses the Blink Developer Tools (formerly WebKit Web Inspector). sponsored by IBM StrongLoop.
All tabs available including: Sources / Timeline / Profiling
Runs Node.js programs inside Chrome DevTools
(using Electron to blend Node.js and Chromium features).
Read this blog post
Comparison to node-inspector
Inspect and validate those suspicions in the memory timeline tab
Capture two or more Heap snapshots
The snapshots capture objects graph
Don’t capture scalar values in the object graph
Use both Summery & Comparison views of the profiles tab
Ignore parentheses
Ignore dimmed
Garbage is collected before each snapshot is taken
Test using incognito mode
to avoid extensions code included in your snapshots...
Focus on the signal
Help the GC out by assigning null to closure variables.
let closureVar = {};
doWork(function callback() {
let data = closureVar.usefulData;
// Do a bunch of work...
// Do a bunch of work...
// Do a bunch of work...
data = null;
});
let theThing = null;
let replaceThing = function () {
let originalThing = theThing;
let unused = function () {
if (originalThing)
console.log("hi");
};
theThing = {
longStr: new Array(1000000).join('*'),
someMethod: function () {
console.log('someMessage...');
}
};
};
setInterval(replaceThing, 1000);
let theThing = null;
let replaceThing = function () {
let originalThing = theThing;
// Define a closure that references originalThing but doesn't ever actually
// get called. But because this closure exists, originalThing will be in the
// lexical environment for all closures defined in replaceThing, instead of
// being optimized out of it. If you remove this function, there is no leak.
let unused = function () {
if (originalThing)
console.log("hi");
};
theThing = {
longStr: new Array(1000000).join('*'),
// While originalThing is theoretically accessible by this function, it
// obviously doesn't use it. But because originalThing is part of the
// lexical environment, someMethod will hold a reference to originalThing,
// and so even though we are replacing theThing with something that has no
// effective way to reference the old value of theThing, the old value
// will never get cleaned up!
someMethod: function () {
console.log('someMessage...');
}
};
// If you add `originalThing = null` here, there is no leak.
};
setInterval(replaceThing, 1000);