Skip to content

Commit

Permalink
Profiler: Encode entry keys a little faster
Browse files Browse the repository at this point in the history
Don't want too much overhead in there.
  • Loading branch information
dgreensp committed Feb 5, 2016
1 parent 2afe4f5 commit 0a22393
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tools/tool-env/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ var formatMs = function (n) {
return String(Math.round(n)).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " ms";
};

var encodeEntryKey = function (entry) {
return entry.join('\t');
};

var decodeEntryKey = function (key) {
return key.split('\t');
};

var globalEntry = [];

var running = false;
Expand Down Expand Up @@ -256,7 +264,7 @@ var Profile = function (bucketName, f) {
}

currentEntry.push(name);
var key = JSON.stringify(currentEntry);
var key = encodeEntryKey(currentEntry);
var start = process.hrtime();
var err = null;
try {
Expand Down Expand Up @@ -294,7 +302,7 @@ var entryName = function (entry) {
};

var entryStats = function (entry) {
return bucketStats[JSON.stringify(entry)];
return bucketStats[encodeEntryKey(entry)];
};

var entryTime = function (entry) {
Expand Down Expand Up @@ -358,7 +366,7 @@ var injectOtherTime = function (entry) {
var name = "other " + entryName(entry);
var other = _.clone(entry);
other.push(name);
bucketStats[JSON.stringify(other)] = {
bucketStats[encodeEntryKey(other)] = {
time: otherTime(entry),
count: entryStats(entry).count,
isOther: true
Expand Down Expand Up @@ -438,7 +446,7 @@ var getTopLevelTotal = function () {
};

var setupReport = function () {
entries = _.map(_.keys(bucketStats), JSON.parse);
entries = _.map(_.keys(bucketStats), decodeEntryKey);
_.each(_.filter(entries, hasSignificantChildren), function (parent) {
injectOtherTime(parent);
});
Expand Down

0 comments on commit 0a22393

Please sign in to comment.