Skip to content

performance: fix tzOffset cache not working for UTC offset strings#53

Open
hotcalpico wants to merge 1 commit intodate-fns:mainfrom
hotcalpico:improve-tzOffset-cache
Open

performance: fix tzOffset cache not working for UTC offset strings#53
hotcalpico wants to merge 1 commit intodate-fns:mainfrom
hotcalpico:improve-tzOffset-cache

Conversation

@hotcalpico
Copy link
Copy Markdown

@hotcalpico hotcalpico commented Apr 12, 2025

Problem

When passing a UTC offset string like +00:00 to the tzOffset function, the cache is not used properly.
This causes significant performance degradation on Android devices 😓

Benchmark

new TZDate()

const start = new Date();
new TZDate(new Date(), "+00:00");
const end = new Date();

console.log(end - start);

// iOS (React Native):      iPhone 11 -> 0ms
// Android (React Native):  Pixel 7a -> 20ms, Galaxy A21 SC-42A -> 7ms, Redmi 12 -> 65ms
//                          (After modification, all 0ms.)

Intl.DateTimeFormat

const start = new Date();
[...Array(1000)].forEach(() => {
  try {
    new Intl.DateTimeFormat("en-GB", {
      timeZone: "+00:00",
      hour: "numeric",
      timeZoneName: "longOffset",
    }).format;
  } catch {}
});
const end = new Date();

console.log(end - start);

// Chrome:                  MacBook Pro 2020 -> 152ms
// iOS (React Native):      iPhone 11 -> 20ms
// Android (React Native):  Pixel 7a -> 5087ms, Galaxy A21 SC-42A -> 2027ms, Redmi 12 -> 5098ms

@kossnocorp kossnocorp added this to Main Aug 1, 2025
@github-project-automation github-project-automation bot moved this to Inbox in Main Aug 1, 2025
@kossnocorp kossnocorp moved this from Inbox to Must in Main Aug 1, 2025
@kossnocorp
Copy link
Copy Markdown
Member

Thank you a lot! I will make sure to test and merge it.

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

Projects

Status: Must

Development

Successfully merging this pull request may close these issues.

2 participants