Skip to content

[General] Avoid unnecessary object allocations#4147

Open
j-piasecki wants to merge 1 commit intomainfrom
@jpiasecki/avoid-unnecessary-allocations
Open

[General] Avoid unnecessary object allocations#4147
j-piasecki wants to merge 1 commit intomainfrom
@jpiasecki/avoid-unnecessary-allocations

Conversation

@j-piasecki
Copy link
Copy Markdown
Member

Description

Removes unnecessary object allocations:

  • configUtils - instead of using Object.assign and creating an object with a single key, the value is now assigned directly
  • eventHandlerUtils - instead of allocating an object for each callback (even when undefined), the value is now assigned directly
  • reanimatedUtils - instead of iterating over the entire config, allocating a [key, value] tuple for each field, iterate over the known callbacks

Test plan

Run the example app

Copilot AI review requested due to automatic review settings May 6, 2026 09:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces avoidable object/tuple allocations in the v3 hook utilities by replacing generic iteration/spread patterns with direct property assignment and fixed-key iteration, lowering per-render/per-gesture overhead in hot paths.

Changes:

  • reanimatedUtils: switch from Object.entries(config) scanning to iterating known callback keys to detect worklet handlers.
  • eventHandlersUtils: avoid creating intermediate objects via conditional spreads when memoizing gesture callbacks.
  • configUtils: replace Object.assign + single-key object creation with direct assignment into the filtered config.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts Avoids Object.entries tuple allocations by iterating the known callback key set when checking for worklet handlers.
packages/react-native-gesture-handler/src/v3/hooks/utils/eventHandlersUtils.ts Avoids conditional-spread object allocations when building the memoized callbacks object.
packages/react-native-gesture-handler/src/v3/hooks/utils/configUtils.ts Avoids allocating { [key]: value } objects by assigning filtered config props directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants