Skip to content

Commit

Permalink
[DI] Improve internal caching algorithm resource overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Nov 5, 2024
1 parent 91c4371 commit 222b2a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 3 additions & 9 deletions packages/dd-trace/src/debugger/devtools_client/status.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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',
Expand Down Expand Up @@ -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)
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 222b2a3

Please sign in to comment.