Commit 9c9583a2 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

inspector: speedup InspectorTest.logMessage

Current implementation might take significant amount of time to
traverse big message. We can reuse builtin JSON.stringify replacer
feature to achieve big performance boost.

R=dgozman@chromium.org

Bug: none
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I59c15f3abb951e2aac938436657b18f608df5099
Reviewed-on: https://chromium-review.googlesource.com/c/1270263Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56484}
parent b8f8deaf
......@@ -33,32 +33,30 @@ InspectorTest.startDumpingProtocolMessages = function() {
}
InspectorTest.logMessage = function(originalMessage) {
var message = JSON.parse(JSON.stringify(originalMessage));
if (message.id)
message.id = "<messageId>";
const nonStableFields = new Set([
'objectId', 'scriptId', 'exceptionId', 'timestamp', 'executionContextId',
'callFrameId', 'breakpointId', 'bindRemoteObjectFunctionId',
'formatterObjectId', 'debuggerId'
]);
var objects = [ message ];
while (objects.length) {
var object = objects.shift();
if (object && object.name === '[[StableObjectId]]')
object.value = '<StablectObjectId>';
for (var key in object) {
if (nonStableFields.has(key))
object[key] = `<${key}>`;
else if (typeof object[key] === "string" && object[key].match(/\d+:\d+:\d+:\d+/))
object[key] = object[key].substring(0, object[key].lastIndexOf(':')) + ":<scriptId>";
else if (typeof object[key] === "object")
objects.push(object[key]);
}
}
const message = JSON.parse(JSON.stringify(originalMessage, replacer.bind(null, Symbol(), nonStableFields)));
if (message.id)
message.id = '<messageId>';
InspectorTest.logObject(message);
return originalMessage;
function replacer(stableIdSymbol, nonStableFields, name, val) {
if (nonStableFields.has(name))
return `<${name}>`;
if (name === 'internalProperties') {
const stableId = val.find(prop => prop.name === '[[StableObjectId]]');
if (stableId)
stableId.value[stableIdSymbol] = true;
}
if (val && val[stableIdSymbol])
return '<StablectObjectId>';
return val;
}
}
InspectorTest.logObject = function(object, title) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment