Skip to content

Commit 005e5e7

Browse files
authored
Merge pull request #188 from webcomponents/fix-perf-regressions
Fix recent perf regressions
2 parents 7270b48 + 6f219d4 commit 005e5e7

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

packages/custom-elements/src/CustomElementInternals.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ export default class CustomElementInternals {
287287
upgradeReaction(element) {
288288
try {
289289
const definition = this._lookupACustomElementDefinition(
290-
/** @type {!Document} */ (element.ownerDocument),
291-
element.namespaceURI, element.localName);
290+
/** @type {!Document} */ (element.ownerDocument), element.localName);
292291
if (definition) {
293292
this._upgradeAnElement(element, definition);
294293
}
@@ -393,19 +392,16 @@ export default class CustomElementInternals {
393392
}
394393

395394
/**
396-
* Runs HTML's 'look up a custom element definition'.
395+
* Runs HTML's 'look up a custom element definition', excluding the namespace
396+
* check.
397397
*
398398
* @private
399399
* @param {!Document} doc
400-
* @param {string} namespace
401400
* @param {string} localName
402401
* @return {!CustomElementDefinition|undefined}
403402
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#look-up-a-custom-element-definition
404403
*/
405-
_lookupACustomElementDefinition(doc, namespace, localName) {
406-
// The namespace must be the HTML namespace.
407-
if (namespace !== NS_HTML) return;
408-
404+
_lookupACustomElementDefinition(doc, localName) {
409405
// The document must be associated with a registry.
410406
const registry = doc.__CE_registry;
411407
if (!registry) return;

packages/custom-elements/src/CustomElementRegistry.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export default class CustomElementRegistry {
7878
* but the list of elements is only populated during a flush after which
7979
* all of the entries are removed. DO NOT edit outside of `#_flush`.
8080
* @private
81-
* @type {!Map<string, !Array<!HTMLElement>>}
81+
* @type {!Array<string>}
8282
*/
83-
this._elementsWithPendingDefinitions = new Map();
83+
this._unflushedLocalNames = [];
8484

8585
/**
8686
* @private
@@ -102,7 +102,7 @@ export default class CustomElementRegistry {
102102
this.internal_assertCanDefineLocalName(localName);
103103

104104
this._localNameToConstructorGetter.set(localName, constructorGetter);
105-
this._elementsWithPendingDefinitions.set(localName, []);
105+
this._unflushedLocalNames.push(localName);
106106

107107
// If we've already called the flush callback and it hasn't called back yet,
108108
// don't call it again.
@@ -124,7 +124,7 @@ export default class CustomElementRegistry {
124124
this.internal_assertCanDefineLocalName(localName);
125125

126126
this.internal_reifyDefinition(localName, constructor);
127-
this._elementsWithPendingDefinitions.set(localName, []);
127+
this._unflushedLocalNames.push(localName);
128128

129129
// If we've already called the flush callback and it hasn't called back yet,
130130
// don't call it again.
@@ -234,7 +234,11 @@ export default class CustomElementRegistry {
234234
*/
235235
const elementsWithStableDefinitions = [];
236236

237-
const elementsWithPendingDefinitions = this._elementsWithPendingDefinitions;
237+
const unflushedLocalNames = this._unflushedLocalNames;
238+
const elementsWithPendingDefinitions = new Map();
239+
for (let i = 0; i < unflushedLocalNames.length; i++) {
240+
elementsWithPendingDefinitions.set(unflushedLocalNames[i], []);
241+
}
238242

239243
this._internals.patchAndUpgradeTree(document, {
240244
upgrade: element => {
@@ -262,7 +266,10 @@ export default class CustomElementRegistry {
262266
}
263267

264268
// Upgrade elements with 'pending' definitions in the order they were defined.
265-
elementsWithPendingDefinitions.forEach((pendingUpgradableElements, localName) => {
269+
for (let i = 0; i < unflushedLocalNames.length; i++) {
270+
const localName = unflushedLocalNames[i];
271+
const pendingUpgradableElements = elementsWithPendingDefinitions.get(localName);
272+
266273
// Attempt to upgrade all applicable elements.
267274
for (let i = 0; i < pendingUpgradableElements.length; i++) {
268275
this._internals.upgradeReaction(pendingUpgradableElements[i]);
@@ -273,9 +280,9 @@ export default class CustomElementRegistry {
273280
if (deferred) {
274281
deferred.resolve(undefined);
275282
}
276-
});
283+
}
277284

278-
elementsWithPendingDefinitions.clear();
285+
unflushedLocalNames.length = 0;
279286
}
280287

281288
/**
@@ -319,8 +326,7 @@ export default class CustomElementRegistry {
319326
// resolved early here even though it might fail later when reified.
320327
const anyDefinitionExists = this._localNameToDefinition.has(localName) ||
321328
this._localNameToConstructorGetter.has(localName);
322-
const definitionHasFlushed =
323-
!this._elementsWithPendingDefinitions.has(localName);
329+
const definitionHasFlushed = this._unflushedLocalNames.indexOf(localName) === -1;
324330
if (anyDefinitionExists && definitionHasFlushed) {
325331
deferred.resolve(undefined);
326332
}

0 commit comments

Comments
 (0)