Skip to content

Commit b0c868c

Browse files
committed
dont cache unknown size for now, more test logging
1 parent bdaac96 commit b0c868c

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

smoke-tests/test/fixtures/setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const getCleanPaths = async () => {
7474
}
7575

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

8080
// setup fixtures

smoke-tests/test/large-install.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ t.test('large install', async t => {
3636

3737
t.test('large install, no lock and low memory', async t => {
3838
// Run the same install but with no lockfile and constrained max-old-space-size
39-
await t.resolves(runTest(t, { lowMemory: true }))
39+
const { stdout } = await runTest(t, { lowMemory: true })
40+
t.match(stdout, /added \d+ packages/)
4041
})

workspaces/arborist/lib/arborist/index.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,33 @@ class PackumentCache extends LRUCache {
5050

5151
constructor ({ heapFactor = 0.25, maxEntryFactor = 0.5, sizeKey = '_contentLength' } = {}) {
5252
const maxSize = Math.floor(PackumentCache.#heapLimit * heapFactor)
53+
const maxEntrySize = maxSize * maxEntryFactor
5354
super({
5455
maxSize,
55-
maxEntrySize: maxSize * maxEntryFactor,
56-
sizeCalculation: (p) => {
57-
// I saw some requests without a content length once but can't reproduce anymore
58-
// lru cache will error if sizeCalculation isnt a positive number
59-
if (p[sizeKey]) {
60-
return p[sizeKey]
61-
}
62-
// Get the current average size of packuments in the cache
63-
// Won't work if cache is empty or no items have a size
64-
if (this.calculatedSize && this.size) {
65-
return this.calculatedSize / this.size
66-
}
67-
// Some very wrong random guess at global average packument size
68-
return 1_000_000
69-
},
56+
maxEntrySize,
57+
// Don't cache if we dont know the size
58+
sizeCalculation: (p) => p[sizeKey] || maxEntrySize + 1,
7059
dispose: (v, k) => {
7160
this.#disposed.add(k)
72-
this.#log('dispose', k)
61+
this.#log(k, 'dispose')
7362
},
7463
})
7564
this.#sizeKey = sizeKey
65+
this.#log(`heap:${PackumentCache.#heapLimit} maxSize:${maxSize} maxEntrySize:${maxEntrySize}`)
7666
}
7767

7868
set (k, v, ...args) {
79-
if (this.#disposed.has(k)) {
69+
const disposed = this.#disposed.has(k)
70+
if (disposed) {
8071
this.#disposed.delete(k)
81-
this.#log('set disposed', k)
82-
}
83-
if (!v[this.#sizeKey]) {
84-
this.#log('no size', k)
8572
}
73+
this.#log(k, 'set', `size:${v[this.#sizeKey]} disposed:${disposed}`)
8674
return super.set(k, v, ...args)
8775
}
8876

8977
has (k, ...args) {
9078
const has = super.has(k, ...args)
91-
this.#log(`cache-${has ? 'hit' : 'miss'}`, k)
79+
this.#log(k, `cache-${has ? 'hit' : 'miss'}`)
9280
return has
9381
}
9482
}

0 commit comments

Comments
 (0)