-
Notifications
You must be signed in to change notification settings - Fork 24.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: constant time JSTimers/_callTimer #49921
base: main
Are you sure you want to change the base?
perf: constant time JSTimers/_callTimer #49921
Conversation
Hi @dagohan! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
This code is no longer used in the new architecture, so we want to avoid making changes to it unless absolutely necessary. I assume the profile results were gotten from a benchmark? Could you share this so we can evaluate whether this is a representative scenario for a real-world application? |
The profiling results were obtained from a real-world app in production (first 12 seconds of startup). Let me know if you need specifics on the benchmarking setup. |
I'm really curious what your startup path looks like if it takes 12 seconds, and how this timers code makes up 1 second of it! |
actual startup duration is around 8 seconds; profiling captured some post-startup activity during startup, a burst of async operations creates many promises and background jobs with intervals, triggering _callTimer frequently - something typical for app startups this issue isn't limited to startup |
Summary:
JSTimers.js
manages the callbacks of setTimeout/setInterval/Promises/etc_callTimer
function is called when its time to call atimerID
's callbackfinding the data of the provided
timerID
has a dynamic performance characteristicit depends on how many timers are active at that time due to use of "Array.indexOf"
this change uses a Map lookup to have a constant-time timerID data fetch.
device: Galaxy A32
current: Array.indexOf usage profiling

this PR: Map.get profiling

Changelog:
Pick one each for the category and type tags:
[INTERNAL] [FIXED] - constant time JSTimers/_callTimer
Test Plan:
packages/react-native/Libraries/Core/Timers/__tests__/JSTimers-test.js
tests passes