Skip to content

Commit

Permalink
swap for lru-cache with 10KB
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Dec 3, 2024
1 parent 1be89a5 commit 5f598cb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/next/src/build/output/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bold, green, magenta, red, yellow, white } from '../../lib/picocolors'
import { LRUCache } from '../../server/lib/lru-cache'

export const prefixes = {
wait: white(bold('○')),
Expand Down Expand Up @@ -76,15 +77,12 @@ export function trace(...message: any[]) {
prefixedLog('trace', ...message)
}

const warnOnceMessages = new Set()
export function warnOnce(...message: any[]) {
if (!warnOnceMessages.has(message[0])) {
if (warnOnceMessages.size > 1000) {
// delete the oldest message (FIFO) to prevent memory leak
warnOnceMessages.delete(warnOnceMessages.values().next().value)
}
warnOnceMessages.add(message.join(' '))
const warnOnceCache = new LRUCache<string>(10_000, (message) => message.length)

export function warnOnce(...message: any[]) {
const key = message.join(' ')
if (!warnOnceCache.has(key)) {
warnOnceCache.set(key)
warn(...message)
}
}

0 comments on commit 5f598cb

Please sign in to comment.