Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure cache/lru stores are treated as dictionaries by v8 #57

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/lru-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ LRUCache.prototype.reset = function () {
this._lru = 0 // least recently used
this._length = 0 // number of items in the list
this._itemCount = 0

// Ensure the cache/lru stores are treated as dictionaries
// Otherwise a pathological case can occur in v8 that degrades performance
// See https://github.com/isaacs/node-lru-cache/issues/54 and
// https://code.google.com/p/v8/issues/detail?id=4518 for more details
this._cache[200000] = this._lruList[200000] = true
delete this._cache[200000]
delete this._lruList[200000]
}

LRUCache.prototype.dump = function () {
Expand Down