Skip to content

Instantly share code, notes, and snippets.

Instrumenting a Polymer 1.x App with User Timing API

The User Timing API let's us visualize custom timing intervals using the dev tools that are built into your web browser. While this is useful for a lot of different cases, one fun trick is to use this API to visualize the cost of the custom elements in your Polymer app.

Polymer has a few key methods whose invokations tend to represent the majority of time spent creating and initializing Polymer custom elements. Let's collect the methods we want to measure in an array:

var instrumentedMethods = [
  // Standard custom element lifecycle callbacks:
 'attachedCallback',
@cdata
cdata / three-clone-gltf.js
Created November 8, 2017 23:26
A quick hack to clone a Three.js GLTF scene without re-loading or re-parsing the source.
const cloneGltf = (gltf) => {
const clone = {
animations: gltf.animations,
scene: gltf.scene.clone(true)
};
const skinnedMeshes = {};
gltf.scene.traverse(node => {
if (node.isSkinnedMesh) {
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyd2dj3xmcjfhk9icxWNFLQ3umm23AxIxf+sa8N0hKi8xLV/cmITo3WZMKIYuSvAOzX4BDhHnd+YTmzvxQeiJ8Awfe3ZKoeYFXlVSqA64rTSGHZ/vIjkuCv+ebBe9Q4h5RlPTv2UDtKTAWKUeYxp5UmZLzf2hyE981yFuI0E8oyn/MNsY5PaEQi0m6PTGddy58gHW45gLPkPIEvwDsIuvKn00jodhT1iLNPmqZPl/jz1VUq3l8+yw1ZjwrBfMoygTycIGnZ2o96hcVkGTqCfoonGAScRZoCbDvdhL4W9uzfpgeIuTllzks3DOITLqHz0UXcVmkiTBaVRFHTv6io7Eh cdata@cdata-macbookpro2.roam.corp.google.com
import { LRUCache } from './lru-cache.js';
const FirebaseQueryAction = {
snapshotReceived: 'FIREBASE_QUERY_SNAPSHOT_RECEIVED',
created: 'FIREBASE_QUERY_CREATED'
};
const FirebaseQueryActionCreatorCache = (maxRealtimeQueries = 10) => {
const cache = new LRUCache(
maxRealtimeQueries,
import {html as H} from 'lit-html';
let foo;
let f = () => html`<div>${wrap(html`${foo}`)}</div>`;
functino wrap(v) => html`<pre>${v}</pre>`;
{
template,
@cdata
cdata / hi
Last active May 17, 2017 21:03
-KkK6Y0a2WVqKBtu_ZQe
<script>
/**
* The first argument is always a reference to the immediate parent node
* relative to where the directive annotation occurs in the template.
*/
Polymer.Directive.formatted = function(node, data) {
node.innerHTML = `<h1>${data.title}</h1><span>${data.body}</span>`;
};
/**
@cdata
cdata / x-special-anchors.html
Last active March 17, 2017 06:13
Directive strawman
<script>
// Directives are functions that live on named properties
// in the Polymer.Directive namespace.
// Directives are very similar to annotated computed effects.
// When called, the first argument is always a node. The rest of
// the arguments are the dependencies expressed in the annotation
// where the directive is used.
// Since directives can be used wherever an annotated computed
// effect might be used, the return value - if any - may be
// assigned to the value of a node property or its text content.
<link rel="import" href="../polymer/src/lib/experimental/factor.html">
<dom-module id="x-light">
<template>
<!-- Stylesheet is appended to the owner root when attached. -->
<style>
#greeting {
color: red;
}
</style>
<!-- Template contents are stamped to <x-light>'s light DOM. -->
@cdata
cdata / test.md
Last active January 12, 2017 01:15

<a href="http://google.com">An link</a>