Skip to content

Commit

Permalink
dont cache unknown size for now, more test logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed May 6, 2024
1 parent d4f2725 commit 465827e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion smoke-tests/test/fixtures/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const getCleanPaths = async () => {
}

module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy = false } = {}) => {
const debugLog = debug || CI ? (...a) => console.error(...a) : () => {}
const debugLog = debug || CI ? (...a) => t.comment(...a) : () => {}
const cleanPaths = await getCleanPaths()

// setup fixtures
Expand Down
3 changes: 2 additions & 1 deletion smoke-tests/test/large-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ t.test('large install', async t => {

t.test('large install, no lock and low memory', async t => {
// Run the same install but with no lockfile and constrained max-old-space-size
await t.resolves(runTest(t, { lowMemory: true }))
const { stdout } = await runTest(t, { lowMemory: true })
t.match(stdout, /added \d+ packages/)
})
32 changes: 10 additions & 22 deletions workspaces/arborist/lib/arborist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,33 @@ class PackumentCache extends LRUCache {

constructor ({ heapFactor = 0.25, maxEntryFactor = 0.5, sizeKey = '_contentLength' } = {}) {
const maxSize = Math.floor(PackumentCache.#heapLimit * heapFactor)
const maxEntrySize = maxSize * maxEntryFactor
super({
maxSize,
maxEntrySize: maxSize * maxEntryFactor,
sizeCalculation: (p) => {
// I saw some requests without a content length once but can't reproduce anymore
// lru cache will error if sizeCalculation isnt a positive number
if (p[sizeKey]) {
return p[sizeKey]
}
// Get the current average size of packuments in the cache
// Won't work if cache is empty or no items have a size
if (this.calculatedSize && this.size) {
return this.calculatedSize / this.size
}
// Some very wrong random guess at global average packument size
return 1_000_000
},
maxEntrySize,
// Don't cache if we dont know the size
sizeCalculation: (p) => p[sizeKey] || maxEntrySize + 1,
dispose: (v, k) => {
this.#disposed.add(k)
this.#log('dispose', k)
this.#log(k, 'dispose')
},
})
this.#sizeKey = sizeKey
this.#log(`heap:${PackumentCache.#heapLimit} maxSize:${maxSize} maxEntrySize:${maxEntrySize}`)
}

set (k, v, ...args) {
if (this.#disposed.has(k)) {
const disposed = this.#disposed.has(k)
if (disposed) {
this.#disposed.delete(k)
this.#log('set disposed', k)
}
if (!v[this.#sizeKey]) {
this.#log('no size', k)
}
this.#log(k, 'set', `size:${v[this.#sizeKey]} disposed:${disposed}`)
return super.set(k, v, ...args)
}

has (k, ...args) {
const has = super.has(k, ...args)
this.#log(`cache-${has ? 'hit' : 'miss'}`, k)
this.#log(k, `cache-${has ? 'hit' : 'miss'}`)
return has
}
}
Expand Down

0 comments on commit 465827e

Please sign in to comment.