Last active
May 1, 2021 15:42
-
-
Save ebidel/57c9e9379ec6b0bda16d to your computer and use it in GitHub Desktop.
Polymer performance numbers bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){(function printStats(){var loadTimes=window.chrome.loadTimes();firstPaint=loadTimes.firstPaintTime*1000;firstPaintTime=firstPaint-(loadTimes.startLoadTime*1000);console.info('First paint took',firstPaintTime,'ms');console.info('Load took',performance.timing.loadEventStart-performance.timing.navigationStart,'ms');var instances=0;if(parseFloat(Polymer.version)<1){instances=[].slice.call(document.querySelectorAll('html /deep/ *')).filter(function(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}).length;}else{instances=Polymer.telemetry.instanceCount;}console.info('Custom element instances:',instances);var reflectCount=0;if(Polymer.telemetry){console.info('=== Properties set to reflectToAttribute ===');Polymer.telemetry.registrations.forEach(function(el){for(var prop in el.properties){if(el.properties[prop].reflectToAttribute){console.log(el.is+'.'+prop);reflectCount++;}}});}else{console.info('=== Properties set to reflect ===');Polymer.elements.forEach(function(el){for(var prop in el.prototype.publish){var propVal=el.prototype.publish[prop];if(propVal&&propVal.reflect){console.log(el.name+'.'+prop);reflectCount++;}}});}console.info('Total properties set to reflectToAttribute:',reflectCount);var imports=document.querySelectorAll('link[rel="import"]');var table=[];var totalDuration=0;console.info('=== HTML Imports load times ===');[].forEach.call(imports,function(link){var entries=performance.getEntriesByName(link.href);entries.forEach(function(e){table.push({url:e.name,ms:e.duration});totalDuration+=e.duration;});});console.log(imports.length+' imports loaded from the main page. Total time: '+totalDuration+'ms');console.table(table);})();})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function printStats() { | |
// First paint | |
var loadTimes = window.chrome.loadTimes(); | |
firstPaint = loadTimes.firstPaintTime * 1000; | |
firstPaintTime = firstPaint - (loadTimes.startLoadTime * 1000); | |
console.info('First paint took', firstPaintTime, 'ms'); | |
// Page load. | |
console.info('Load took', performance.timing.loadEventStart - performance.timing.navigationStart, 'ms'); | |
// # of custom element instances | |
var instances = 0; | |
if (parseFloat(Polymer.version) < 1) { // Polymer 0.5. | |
instances = Array.from(document.querySelectorAll('html /deep/ *')).filter(el => { | |
const isAttr = el.getAttribute('is'); | |
return el.localName.includes('-') || isAttr && isAttr.includes('-'); | |
}).length; | |
} else { | |
instances = Polymer.telemetry.instanceCount; | |
} | |
console.info('Custom element instances:', instances); | |
// Properties being reflected to attributes. | |
var reflectCount = 0; | |
if (Polymer.telemetry) { | |
console.info('=== Properties set to reflectToAttribute ==='); | |
Polymer.telemetry.registrations.forEach(function(el) { | |
for (var prop in el.properties) { | |
if (el.properties[prop].reflectToAttribute) { | |
console.log(el.is + '.' + prop); | |
reflectCount++; | |
} | |
} | |
}); | |
} else { // 0.5 code | |
console.info('=== Properties set to reflect ==='); | |
Polymer.elements.forEach(function(el) { | |
for (var prop in el.prototype.publish) { | |
var propVal = el.prototype.publish[prop]; | |
if (propVal && propVal.reflect) { | |
console.log(el.name + '.' + prop); | |
reflectCount++; | |
} | |
} | |
}); | |
} | |
console.info('Total properties set to reflectToAttribute:', reflectCount); | |
// Main page imports perf. | |
var imports = document.querySelectorAll('link[rel="import"]'); | |
var table = []; | |
var totalDuration = 0; | |
console.info('=== HTML Imports load times ==='); | |
[].forEach.call(imports, function(link) { | |
var entries = performance.getEntriesByName(link.href); | |
entries.forEach(function(e) { | |
table.push({url: e.name, ms: e.duration}); | |
totalDuration += e.duration; | |
}); | |
}); | |
console.log(imports.length + ' imports loaded from the main page. Total time: ' + totalDuration + 'ms'); | |
console.table(table); | |
})(); |
@ebidel any reason the times would be negative?
@ebidel what do you think the two questions above? I also have questions about these two issues.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is reflectToAttribute particularly resource intensive? How does it affect performance?