From 465827ece3cd029a7b0904c0f70e4088cda60651 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Fri, 3 May 2024 10:54:08 -0700 Subject: [PATCH] dont cache unknown size for now, more test logging --- smoke-tests/test/fixtures/setup.js | 2 +- smoke-tests/test/large-install.js | 3 ++- workspaces/arborist/lib/arborist/index.js | 32 +++++++---------------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/smoke-tests/test/fixtures/setup.js b/smoke-tests/test/fixtures/setup.js index d2500507119a8..4ac3245f54275 100644 --- a/smoke-tests/test/fixtures/setup.js +++ b/smoke-tests/test/fixtures/setup.js @@ -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 diff --git a/smoke-tests/test/large-install.js b/smoke-tests/test/large-install.js index cc94104d43ebc..a9260c8d3f0f1 100644 --- a/smoke-tests/test/large-install.js +++ b/smoke-tests/test/large-install.js @@ -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/) }) diff --git a/workspaces/arborist/lib/arborist/index.js b/workspaces/arborist/lib/arborist/index.js index 263636c66edc8..2c41c6a911fc7 100644 --- a/workspaces/arborist/lib/arborist/index.js +++ b/workspaces/arborist/lib/arborist/index.js @@ -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 } }