Skip to content

fix(js): fixed caching performance issues#1604

Open
eric-zaharia wants to merge 4 commits intov4from
fix/localstorage-cache-perf
Open

fix(js): fixed caching performance issues#1604
eric-zaharia wants to merge 4 commits intov4from
fix/localstorage-cache-perf

Conversation

@eric-zaharia
Copy link
Contributor

Reduces localStorage blocking in createBrowserLocalStorageCache to improve INP by merging two filter passes into one (cutting get() from 2 reads + 2 writes to 1 read + 1 write) and yielding to the main thread via scheduler.yield() / setTimeout before heavy work in get(), set(), and delete().

@eric-zaharia eric-zaharia self-assigned this Feb 16, 2026
@eric-zaharia eric-zaharia requested a review from Fluf22 February 17, 2026 08:29
Comment on lines +7 to +9
const g: any = typeof globalThis !== 'undefined' ? globalThis : undefined;

if (g && g.scheduler && g.scheduler.yield) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not directly

Suggested change
const g: any = typeof globalThis !== 'undefined' ? globalThis : undefined;
if (g && g.scheduler && g.scheduler.yield) {
if (typeof globalThis !== 'undefined' && globalThis && globalThis.scheduler && globalThis.scheduler.yield) {

const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;

return !isExpired;
return cacheItem.timestamp + timeToLive >= new Date().getTime();
Copy link
Contributor

@Fluf22 Fluf22 Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we could extract new Date().getTime() outside of the filter loop?
So it's computed once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments