[PROF-13950] ⚡️ Memoize getTimeZone to avoid repeated Intl.DateTimeFormat instantiation#4302
Draft
thomasbertet wants to merge 2 commits intomainfrom
Draft
[PROF-13950] ⚡️ Memoize getTimeZone to avoid repeated Intl.DateTimeFormat instantiation#4302thomasbertet wants to merge 2 commits intomainfrom
thomasbertet wants to merge 2 commits intomainfrom
Conversation
…rmat instantiation new Intl.DateTimeFormat() is expensive (locale negotiation + timezone resolution) and was called on every VIEW_UPDATED event. Since the timezone is static for the page lifetime, compute it once at module load time instead.
Switch from eager module-level computation to lazy caching: compute the timezone on first call and cache it, avoiding any cost at module load time.
Bundles Sizes Evolution
🚀 CPU PerformancePending... 🧠 Memory PerformancePending... |
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 6b7b260 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
new Intl.DateTimeFormat()can be an expensive browser API call (involves locale negotiation and timezone resolution). It was being executed on everyVIEW_UPDATEDlifecycle event viagetTimeZone()inprocessViewUpdate().VIEW_UPDATEDfires frequently: on every captured action, error, resource, long task, CLS/LCP/FCP update, context change, and more. Since the timezone never changes during a page session, this repeated work was pure waste.Related: PROF-13950
Identified while looking at some RUM Browser Profiler INP:

Changes
Memoize the timezone value at module load time in
packages/core/src/tools/utils/timezone.ts.resolveTimeZone()runs once, the result is stored in a module-level constant, andgetTimeZone()simply returns it.No behavior change — the returned value is identical.
Test instructions
No specific repro needed. Verify that
getTimeZone()still returns the correct timezone string in unit tests.Checklist