-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
New implementation of PerformanceObserver and related APIs (fixes #45122) #45206
Conversation
2ed73a9
to
5de7d48
Compare
Pushed early changes for approach review. Still working on updating TurboModule and its spec to match new API. |
5de7d48
to
7b45779
Compare
Ready for an early review. Will undo changes related to exposing Performance TurboModule and still needs some testing from my side. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a larger refactor than I was expecting, but I like the direction we're taking here. I made an initial pass on the PR (please forgive the amount of comments, this is very large). Please let me know what you think, and thanks so much for this!
packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp
Outdated
Show resolved
Hide resolved
...ges/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp
Show resolved
Hide resolved
@@ -28,6 +30,14 @@ namespace facebook::react { | |||
return std::make_shared<NativeIdleCallbacks>(jsInvoker); | |||
} | |||
|
|||
if (name == NativePerformance::kModuleName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to enable this by default yet, until we've had a chance to test it thoroughly at Meta first. Please revert this for the PR (I understand you still need it to test it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the comment about this being temporary as well :P
...ges/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp
Show resolved
Hide resolved
...ges/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserverRegistry.h
Outdated
Show resolved
Hide resolved
packages/react-native/src/private/webapis/performance/specs/NativePerformanceObserver.js
Show resolved
Hide resolved
844f334
to
8a77bcd
Compare
@rubennorte I've allowed myself to resolve comments that I think are corrected :) The remaining ones I still need some input. FYI: still not fully tested on my side 😅 |
@@ -28,6 +30,14 @@ namespace facebook::react { | |||
return std::make_shared<NativeIdleCallbacks>(jsInvoker); | |||
} | |||
|
|||
if (name == NativePerformance::kModuleName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the comment about this being temporary as well :P
...ages/react-native/ReactCommon/react/nativemodule/defaults/React-defaultsnativemodule.podspec
Outdated
Show resolved
Hide resolved
...ges/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
...ges/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/BoundedConsumableBuffer.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserverRegistry.h
Outdated
Show resolved
Hide resolved
caf3b65
to
8772490
Compare
packages/react-native/src/private/webapis/performance/specs/NativePerformanceObserver.js
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/BoundedConsumableBuffer.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryCircularBuffer.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryBuffer.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryCircularBuffer.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryBuffer.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryBuffer.h
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryCircularBuffer.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryLinearBuffer.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryKeyedBuffer.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryKeyedBuffer.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryLinearBuffer.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserverRegistry.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserverRegistry.h
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.h
Outdated
Show resolved
Hide resolved
e57a510
to
8fe46c2
Compare
packages/react-native/ReactCommon/react/performance/timeline/CircularBuffer.h
Show resolved
Hide resolved
packages/react-native/src/private/webapis/performance/PerformanceObserver.js
Outdated
Show resolved
Hide resolved
@rubennorte has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp
Outdated
Show resolved
Hide resolved
...ges/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserver.cpp
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceObserverRegistry.cpp
Outdated
Show resolved
Hide resolved
packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.h
Show resolved
Hide resolved
@rubennorte has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
} | ||
|
||
if (observedTypes_.contains(entry.entryType)) { | ||
buffer_.push_back(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, we're not scheduling the task to notify the observer anywhere :S
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to get those unittests running locally somehow 🥲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it again, we call the callback
below, which is passed from NativePerformanceObserver
to schedule a task 🤔
@rubennorte merged this pull request in 38b3b21. |
This pull request was successfully merged by @robik in 38b3b21 When will my fix make it into a release? | How to file a pick request? |
Summary:
Fix #45122.
performance.mark is currently O(1) but performance.clearMark is O(n) (being n the number of entries in the buffer), which makes this operation very slow.
Changes overview
PerformanceEntryBuffer
abstraction with the following subtypes, that differ on how entries are stored:PerformanceEntryCircularBuffer
- stores them in a ring buffer that was already implemented, removed key lookup cache (BoundedConsumableBuffer
)PerformanceEntryKeyedBuffer
- stores them in aunordered_map
, allowing for faster retrieval by typePerformanceEntryLinearBuffer
- a simple infinite buffer based onstd::vector
, currently used in aPerformanceObserver
PerformanceObserver
abstraction on native side.PerformanceObserverRegistry
that collects active observers and forwards entries to observers that should retrieve them.cpp
files to reduce potential compilation time slowdown. As thePerformanceEntryReporter
can be included from anywhere in the code, it will be beneficial to make header files as light as possible.[[nodiscard]]
attributesPerformanceObserver
can be created from native-sideStandards covered:
Changelog:
[GENERAL] [CHANGED] - Refactored
performance-timeline
module, which should improve performance ofperformance.clearMarks
andperformance.clearMeasures
Test Plan:
n/a