Skip to content

Commit

Permalink
Merge pull request Netflix#695 from michaelbpaulson/finish-hard-keys
Browse files Browse the repository at this point in the history
feat(performance): The last of the statically referred to keys.
  • Loading branch information
ThePrimeagen committed Jan 14, 2016
2 parents e7ac8f8 + 57f8054 commit 36cb896
Show file tree
Hide file tree
Showing 47 changed files with 120 additions and 230 deletions.
6 changes: 2 additions & 4 deletions lib/deref/hasValidParentReference.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var __parent = require("./../internal/parent");
var __invalidated = require("./../internal/invalidated");
module.exports = function fromWhenceYeCame() {
var reference = this._referenceContainer;

Expand All @@ -20,12 +18,12 @@ module.exports = function fromWhenceYeCame() {
}

// Its been disconnected (set over or collected) from the graph.
if (reference && reference[__parent] === undefined) {
if (reference && reference.ツparent === undefined) {
return false;
}

// The reference has expired but has not been collected from the graph.
if (reference && reference[__invalidated]) {
if (reference && reference.ツinvalidated) {
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/get/followReference.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var hardLink = require("./../get/util/hardlink");
var createHardlink = hardLink.create;
var createHardlink = require("./../support/createHardlink");
var onValue = require("./../get/onValue");
var isExpired = require("./../get/util/isExpired");
var $ref = require("./../types/ref");
Expand Down
6 changes: 2 additions & 4 deletions lib/get/getCache.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var $modelCreated = require("./../internal/model-created");
var isInternalKey = require("./../support/isInternalKey");

/**
Expand Down Expand Up @@ -42,8 +41,7 @@ function _copyCache(node, out, fromKey) {
// 2: A $type-value node.
// 3: undefined
// We will strip out 3
return (!isInternalKey(k) || k === $modelCreated) &&
node[k] !== undefined;
return !isInternalKey(k) && node[k] !== undefined;
}).
forEach(function(key) {
var cacheNext = node[key];
Expand All @@ -56,7 +54,7 @@ function _copyCache(node, out, fromKey) {
// Paste the node into the out cache.
if (cacheNext.$type) {
var isObject = cacheNext.value && typeof cacheNext.value === "object";
var isUserCreatedcacheNext = !cacheNext[$modelCreated];
var isUserCreatedcacheNext = !cacheNext.ツmodelCreated;
var value;
if (isObject || isUserCreatedcacheNext) {
value = cloneBoxedValue(cacheNext);
Expand Down
4 changes: 1 addition & 3 deletions lib/get/getVersion.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
var __version = require("./../internal/version");

module.exports = function _getVersion(model, path) {
// ultra fast clone for boxed values.
var gen = model._getValueSync({
_boxed: true,
_root: model._root,
_treatErrorsAsValues: model._treatErrorsAsValues
}, path, true).value;
var version = gen && gen[__version];
var version = gen && gen.ツversion;
return (version == null) ? -1 : version;
};
3 changes: 1 addition & 2 deletions lib/get/onValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var clone = require("./util/clone");
var $ref = require("./../types/ref");
var $atom = require("./../types/atom");
var $error = require("./../types/error");
var $modelCreated = require("./../internal/model-created");

module.exports = function onValue(model, node, seed, depth, outerResults,
branchInfo, requestedPath, optimizedPath,
Expand Down Expand Up @@ -46,7 +45,7 @@ module.exports = function onValue(model, node, seed, depth, outerResults,

else if (isJSONG) {
var isObject = node.value && typeof node.value === "object";
var isUserCreatedNode = !node[$modelCreated];
var isUserCreatedNode = !node.ツmodelCreated;
if (isObject || isUserCreatedNode) {
valueNode = clone(node);
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/get/onValueType.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var onError = require("./onError");
var onValue = require("./onValue");
var onMissing = require("./onMissing");
var isMaterialized = require("./util/isMaterialzed");
var __invalidated = require("./../internal/invalidated");
var expireNode = require("./../support/expireNode");

/**
Expand Down Expand Up @@ -37,7 +36,7 @@ module.exports = function onValueType(

// If there are expired value, then report it as missing
else if (isExpired(node)) {
if (!node[__invalidated]) {
if (!node.ツinvalidated) {
expireNode(node, model._root.expired, model._root);
}
onMissing(model, path, depth,
Expand Down
4 changes: 1 addition & 3 deletions lib/get/util/clone.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copies the node
var prefix = require("./../../internal/prefix");
var unicodePrefix = require("./../../internal/unicodePrefix");
var $modelCreated = require("./../../internal/model-created");

module.exports = function clone(node) {
var outValue, i, len;
Expand All @@ -10,7 +8,7 @@ module.exports = function clone(node) {
for (i = 0, len = keys.length; i < len; i++) {
var k = keys[i];
var k0 = k.charAt(0);
if (k0 === prefix || k0 === unicodePrefix || k === $modelCreated) {
if (k0 === unicodePrefix) {
continue;
}
outValue[k] = node[k];
Expand Down
20 changes: 0 additions & 20 deletions lib/get/util/hardlink.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/internal/__.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/internal/invalidated.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./../internal/prefix") + "invalidated";
module.exports = require("./unicodePrefix") + "invalidated";
2 changes: 1 addition & 1 deletion lib/internal/key.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./../internal/prefix") + "key";
module.exports = require("./unicodePrefix") + "key";
2 changes: 0 additions & 2 deletions lib/internal/lruPrefix.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/internal/model-created.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = "$modelCreated";
module.exports = require("./unicodePrefix") + "modelCreated";
1 change: 0 additions & 1 deletion lib/internal/offset.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/internal/parent.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./../internal/prefix") + "parent";
module.exports = require("./unicodePrefix") + "parent";
2 changes: 1 addition & 1 deletion lib/internal/path.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./prefix") + "path";
module.exports = require("./unicodePrefix") + "path";
1 change: 0 additions & 1 deletion lib/internal/pathingPrefix.js

This file was deleted.

5 changes: 0 additions & 5 deletions lib/internal/prefix.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/internal/ref-index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./prefix") + "ref-index";
module.exports = require("./unicodePrefix") + "refIndex";
2 changes: 1 addition & 1 deletion lib/internal/ref.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./../internal/prefix") + "ref";
module.exports = require("./unicodePrefix") + "ref";
3 changes: 2 additions & 1 deletion lib/internal/refs-length.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require("./../internal/prefix") + "refs-length";
module.exports = require("./unicodePrefix") + "refsLength";

2 changes: 1 addition & 1 deletion lib/internal/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./../internal/prefix") + "version";
module.exports = require("./unicodePrefix") + "version";
30 changes: 10 additions & 20 deletions lib/invalidate/invalidatePathMaps.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
var __key = require("./../internal/key");
var __ref = require("./../internal/ref");
var __prefix = require("./../internal/prefix");
var __parent = require("./../internal/parent");
var __context = require("./../internal/context");
var __version = require("./../internal/version");
var __refIndex = require("./../internal/ref-index");
var __refsLength = require("./../internal/refs-length");
var createHardlink = require("../support/createHardlink");
var __prefix = require("./../internal/unicodePrefix");

var $ref = require("./../types/ref");

Expand Down Expand Up @@ -41,8 +35,8 @@ module.exports = function invalidatePathMaps(model, pathMapEnvelopes) {
var bound = model._path;
var cache = modelRoot.cache;
var node = bound.length ? getBoundValue(model, bound).value : cache;
var parent = node[__parent] || cache;
var initialVersion = cache[__version];
var parent = node.ツparent || cache;
var initialVersion = cache.ツversion;

var pathMapIndex = -1;
var pathMapCount = pathMapEnvelopes.length;
Expand All @@ -57,7 +51,7 @@ module.exports = function invalidatePathMaps(model, pathMapEnvelopes) {
);
}

var newVersion = cache[__version];
var newVersion = cache.ツversion;
var rootChangeHandler = modelRoot.onChange;

if (isFunction(rootChangeHandler) && initialVersion !== newVersion) {
Expand Down Expand Up @@ -110,10 +104,10 @@ function invalidateReference(value, root, node, version, expired, lru, comparato
var reference = node.value;
var parent = root;

node = node[__context];
node = node.ツcontext;

if (node != null) {
parent = node[__parent] || root;
parent = node.ツparent || root;
} else {

var index = 0;
Expand All @@ -136,12 +130,8 @@ function invalidateReference(value, root, node, version, expired, lru, comparato
parent = results[1];
} while (index++ < count);

if (container[__context] !== node) {
var backRefs = node[__refsLength] || 0;
node[__refsLength] = backRefs + 1;
node[__ref + backRefs] = container;
container[__context] = node;
container[__refIndex] = backRefs;
if (container.ツcontext !== node) {
createHardlink(container, node);
}
}

Expand Down Expand Up @@ -177,7 +167,7 @@ function invalidateNode(
if (branch) {
throw new Error("`null` is not allowed in branch key positions.");
} else if (node) {
key = node[__key];
key = node.ツkey;
}
} else {
parent = node;
Expand Down
28 changes: 11 additions & 17 deletions lib/invalidate/invalidatePathSets.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
var __key = require("./../internal/key");
var __ref = require("./../internal/ref");
var __parent = require("./../internal/parent");
var __context = require("./../internal/context");
var __version = require("./../internal/version");
var __refIndex = require("./../internal/ref-index");
var __refsLength = require("./../internal/refs-length");

var $ref = require("./../types/ref");

Expand Down Expand Up @@ -37,8 +31,8 @@ module.exports = function invalidatePathSets(model, paths) {
var bound = model._path;
var cache = modelRoot.cache;
var node = bound.length ? getBoundValue(model, bound).value : cache;
var parent = node[__parent] || cache;
var initialVersion = cache[__version];
var parent = node.ツparent || cache;
var initialVersion = cache.ツversion;

var pathIndex = -1;
var pathCount = paths.length;
Expand All @@ -53,7 +47,7 @@ module.exports = function invalidatePathSets(model, paths) {
);
}

var newVersion = cache[__version];
var newVersion = cache.ツversion;
var rootChangeHandler = modelRoot.onChange;

if (isFunction(rootChangeHandler) && initialVersion !== newVersion) {
Expand Down Expand Up @@ -106,10 +100,10 @@ function invalidateReference(root, node, version, expired, lru) {
var reference = node.value;
var parent = root;

node = node[__context];
node = node.ツcontext;

if (node != null) {
parent = node[__parent] || root;
parent = node.ツparent || root;
} else {

var index = 0;
Expand All @@ -132,12 +126,12 @@ function invalidateReference(root, node, version, expired, lru) {
parent = results[1];
} while (index++ < count);

if (container[__context] !== node) {
var backRefs = node[__refsLength] || 0;
node[__refsLength] = backRefs + 1;
if (container.ツcontext !== node) {
var backRefs = node.ツrefsLength || 0;
node.ツrefsLength = backRefs + 1;
node[__ref + backRefs] = container;
container[__context] = node;
container[__refIndex] = backRefs;
container.ツcontext = node;
container.ツrefIndex = backRefs;
}
}

Expand Down Expand Up @@ -173,7 +167,7 @@ function invalidateNode(
if (branch) {
throw new Error("`null` is not allowed in branch key positions.");
} else if (node) {
key = node[__key];
key = node.ツkey;
}
} else {
parent = node;
Expand Down
6 changes: 2 additions & 4 deletions lib/lru/collect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var __key = require("./../internal/key");
var __parent = require("./../internal/parent");
var removeNode = require("./../support/removeNode");
var updateNodeAncestors = require("./../support/updateNodeAncestors");

Expand All @@ -23,8 +21,8 @@ module.exports = function collect(lru, expired, totalArg, max, ratioArg, version
total -= size;
if (shouldUpdate === true) {
updateNodeAncestors(node, size, lru, version);
} else if (parent = node[__parent]) {
removeNode(node, parent, node[__key], lru);
} else if (parent = node.ツparent) {
removeNode(node, parent, node.ツkey, lru);
}
node = expired.pop();
}
Expand Down
3 changes: 1 addition & 2 deletions lib/response/get/GetResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var ModelResponse = require("./../ModelResponse");
var checkCacheAndReport = require("./checkCacheAndReport");
var getRequestCycle = require("./getRequestCycle");
var empty = {dispose: function() {}};
var __version = require("./../../internal/version");
var collectLru = require("./../../lru/collect");
var getSize = require("./../../support/getSize");

Expand Down Expand Up @@ -68,7 +67,7 @@ GetResponse.prototype._subscribe = function _subscribe(observer) {
if (this.forceCollect) {
var modelRoot = model._root;
var modelCache = modelRoot.cache;
var currentVersion = modelCache[__version];
var currentVersion = modelCache.ツversion;

collectLru(modelRoot, modelRoot.expired, getSize(modelCache),
model._maxSize, model._collectRatio, currentVersion);
Expand Down
3 changes: 1 addition & 2 deletions lib/response/get/getRequestCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var fastCat = require("./../../get/util/support").fastCat;
var collectLru = require("./../../lru/collect");
var getSize = require("./../../support/getSize");
var AssignableDisposable = require("./../AssignableDisposable");
var __version = require("./../../internal/version");
var InvalidSourceError = require("../../errors/InvalidSourceError");

/**
Expand Down Expand Up @@ -81,7 +80,7 @@ module.exports = function getRequestCycle(getResponse, model, results, observer,

var modelRoot = model._root;
var modelCache = modelRoot.cache;
var currentVersion = modelCache[__version];
var currentVersion = modelCache.ツversion;

collectLru(modelRoot, modelRoot.expired, getSize(modelCache),
model._maxSize, model._collectRatio, currentVersion);
Expand Down
Loading

0 comments on commit 36cb896

Please sign in to comment.