Conversation
| } | ||
| super.emit(eventType, ...args); |
There was a problem hiding this comment.
let's have this method in a else branch and avoid the early return please
There was a problem hiding this comment.
Done — moved the fast path into the else branch and removed the early return. Pushed in 4359d54.
|
The iOS RNTester e2e (Debug) failed on retry_2 while Release passed and the same suite passed on the two previous runs — looks like a flaky simulator. A re-run might clear it. Let me know if anything on the code side needs attention. |
|
This change looks fine but please don't add new Jest tests as we're moving to Fantom to make sure the environment that runtime code runs in tests is as close as the real environment as possible. In this case, the test should be renamed to have the |
Done — converted the added Jest test to a Fantom itest (RCTDeviceEventEmitter-itest.js), renamed with the -itest suffix, and it now uses the public API (DeviceEventEmitter from react-native). All 5 tests pass locally against the Hermes runtime; pushed in 844dd96. |
|
@cortinico has imported this pull request. If you are a Meta employee, you can view this in D121799063. |
|
@cortinico merged this pull request in 7f6043b. |
Summary:
RCTDeviceEventEmitter.emit is one of the hottest paths in React Native:
NativeEventEmitter.emit delegates to it, so every event delivered from
native (scroll, touch, keyboard, app state, ...) goes through this method.
The current implementation wraps every call in Systrace.trace, which
always allocates two closures (a lazy event-name thunk and a callback)
on every emit — even when tracing is disabled, which is the common case.
This changes emit to guard on Systrace.isEnabled() and use
beginEvent/endEvent directly:
zero allocations
and the same begin/end semantics, including endEvent() in a finally
block when a listener throws
Behavior is unchanged; only the fast-path allocations are removed.
Changelog:
[General] [Changed] - RCTDeviceEventEmitter.emit no longer allocates closures on every emit when tracing is disabled, reducing per-event allocation on the native-to-JS event path
Test Plan:
two heap-allocated closures per event