From 222b2a3937e5f3da7f5c2cdca4eaa3ef69deada5 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 5 Nov 2024 20:57:17 +0000 Subject: [PATCH] [DI] Improve internal caching algorithm resource overhead --- package.json | 3 ++- .../dd-trace/src/debugger/devtools_client/status.js | 12 +++--------- yarn.lock | 12 ++++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6450891cad8..37163bdaaca 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,8 @@ "rfdc": "^1.3.1", "semver": "^7.5.4", "shell-quote": "^1.8.1", - "tlhunter-sorted-set": "^0.1.0" + "tlhunter-sorted-set": "^0.1.0", + "ttl-set": "^1.0.0" }, "devDependencies": { "@apollo/server": "^4.11.0", diff --git a/packages/dd-trace/src/debugger/devtools_client/status.js b/packages/dd-trace/src/debugger/devtools_client/status.js index e4ba10d8c55..f464e570caa 100644 --- a/packages/dd-trace/src/debugger/devtools_client/status.js +++ b/packages/dd-trace/src/debugger/devtools_client/status.js @@ -1,6 +1,6 @@ 'use strict' -const LRUCache = require('lru-cache') +const TTLSet = require('ttl-set') const config = require('./config') const request = require('../../exporters/common/request') const FormData = require('../../exporters/common/form-data') @@ -17,13 +17,7 @@ const ddsource = 'dd_debugger' const service = config.service const runtimeId = config.runtimeId -const cache = new LRUCache({ - ttl: 1000 * 60 * 60, // 1 hour - // Unfortunate requirement when using LRUCache: - // It will emit a warning unless `ttlAutopurge`, `max`, or `maxSize` is set when using `ttl`. - // TODO: Consider alternative as this is NOT performant :( - ttlAutopurge: true -}) +const cache = new TTLSet(60 * 60 * 1000) // 1 hour const STATUSES = { RECEIVED: 'RECEIVED', @@ -105,5 +99,5 @@ function onlyUniqueUpdates (type, id, version, fn) { const key = `${type}-${id}-${version}` if (cache.has(key)) return fn() - cache.set(key) + cache.add(key) } diff --git a/yarn.lock b/yarn.lock index ea83a1fee4b..4bb7aa4eb27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2353,6 +2353,11 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz" integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== +fast-fifo@^1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.3.2.tgz#286e31de96eb96d38a97899815740ba2a4f3640c" + integrity sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ== + fast-json-stable-stringify@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz" @@ -4823,6 +4828,13 @@ tslib@^2.4.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b" integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA== +ttl-set@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ttl-set/-/ttl-set-1.0.0.tgz#e7895d946ad9cedfadcf6e3384ea97322a86dd3b" + integrity sha512-2fuHn/UR+8Z9HK49r97+p2Ru1b5Eewg2QqPrU14BVCQ9QoyU3+vLLZk2WEiyZ9sgJh6W8G1cZr9I2NBLywAHrA== + dependencies: + fast-fifo "^1.3.2" + type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz"