Skip to content

fix(js): fixed caching performance issues#1604

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

fix(js): fixed caching performance issues#1604
eric-zaharia wants to merge 6 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
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

I doubt this is the only inefficient promise-related code, but if it works for your use case, lgtm. I personally would add tests and compare with v5 though


function yieldToMain(): Promise<void> {
// eslint-disable-next-line no-undef
const g: any = typeof globalThis !== 'undefined' ? globalThis : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you cast this as any and not Window or something? seems a bit odd to lie to typescript

if (g && g.scheduler && g.scheduler.yield) {
return g.scheduler.yield().catch((error: any) => {
// eslint-disable-next-line no-console
console.error('Failed to yield to main: ', error);
Copy link
Contributor

Choose a reason for hiding this comment

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

what error can happen?

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.

3 participants

Comments