Skip to content

Commit

Permalink
Save 30b by removing sharding from the component recycler. It was act…
Browse files Browse the repository at this point in the history
…ually slightly hurting performance in everything but PhantomJS.
  • Loading branch information
developit committed Aug 5, 2018
1 parent 013c060 commit 7cbaa2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
34 changes: 10 additions & 24 deletions src/vdom/component-recycler.js
@@ -1,23 +1,11 @@
import { Component } from '../component';

/**
* Retains a pool of Components for re-use, keyed on component name.
* Note: since component names are not unique or even necessarily available,
* these are primarily a form of sharding.
* @type {Object.<string, Component[]>}
* Retains a pool of Components for re-use.
* @type {Component[]}
* @private
*/
const components = {};


/**
* Reclaim a component for later re-use by the recycler.
* @param {Component} component The component to collect
*/
export function collectComponent(component) {
let name = component.constructor.name;
(components[name] || (components[name] = [])).push(component);
}
export const recyclerComponents = [];


/**
Expand All @@ -29,8 +17,7 @@ export function collectComponent(component) {
* @returns {import('../component').Component}
*/
export function createComponent(Ctor, props, context) {
let list = components[Ctor.name],
inst;
let inst, i = recyclerComponents.length;

if (Ctor.prototype && Ctor.prototype.render) {
inst = new Ctor(props, context);
Expand All @@ -43,15 +30,14 @@ export function createComponent(Ctor, props, context) {
}


if (list) {
for (let i=list.length; i--; ) {
if (list[i].constructor===Ctor) {
inst.nextBase = list[i].nextBase;
list.splice(i, 1);
break;
}
while (i--) {
if (recyclerComponents[i].constructor===Ctor) {
inst.nextBase = recyclerComponents[i].nextBase;
recyclerComponents.splice(i, 1);
return inst;
}
}

return inst;
}

Expand Down
4 changes: 2 additions & 2 deletions src/vdom/component.js
Expand Up @@ -4,7 +4,7 @@ import { extend } from '../util';
import { enqueueRender } from '../render-queue';
import { getNodeProps } from './index';
import { diff, mounts, diffLevel, flushMounts, recollectNodeTree, removeChildren } from './diff';
import { createComponent, collectComponent } from './component-recycler';
import { createComponent, recyclerComponents } from './component-recycler';
import { removeNode } from '../dom/index';

/**
Expand Down Expand Up @@ -287,7 +287,7 @@ export function unmountComponent(component) {
component.nextBase = base;

removeNode(base);
collectComponent(component);
recyclerComponents.push(component);

removeChildren(base);
}
Expand Down

0 comments on commit 7cbaa2a

Please sign in to comment.