Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2026-04-24 - Precomputing Static Prefixes on Hot Paths
**Learning:** In Node.js, dynamic array allocation (`[]`), array methods like `.filter(Boolean)`, and `.join(':')` inside a hot path (like cache key generation) introduce unnecessary CPU overhead and memory allocation pressure. This is a common performance anti-pattern.
**Action:** Always precompute static segments of strings outside the function scope (e.g. at initialization). Use simple string concatenation or template literals (`${prefix}${key}`) on the hot path to construct keys efficiently.
8 changes: 6 additions & 2 deletions src/cache/createCacheHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ export function createCacheHandler<T = unknown>(options: CacheHandlerOptions<T>)
const l1Cache = new Map<string, { value: unknown; expiresAt: number }>();
const L1_CACHE_TTL = 1000; // 1 second TTL for L1 cache

// Precompute base prefix to avoid array allocations, .filter(), and .join() on every fetch (hot path)
const baseParts = [prefix, version].filter(Boolean);
const basePrefix = baseParts.length > 0 ? `${baseParts.join(':')}:` : '';

/**
* Get the fully qualified key with prefix and version
*/
const getFullKey = (key: string): string => {
const parts = [prefix, version, key].filter(Boolean);
return parts.join(':');
// Check for empty key edge case to match original .filter(Boolean) behavior
return key ? `${basePrefix}${key}` : baseParts.join(':');
};

/**
Expand Down
Loading