Skip to content

perf(Blocks,Block): add deep comparison to block/blocks memo call#4253

Open
jakequade-pc wants to merge 1 commit intoBuilderIO:mainfrom
jakequade-pc:perf-react-native-deep-memo-comparison
Open

perf(Blocks,Block): add deep comparison to block/blocks memo call#4253
jakequade-pc wants to merge 1 commit intoBuilderIO:mainfrom
jakequade-pc:perf-react-native-deep-memo-comparison

Conversation

@jakequade-pc
Copy link
Copy Markdown

@jakequade-pc jakequade-pc commented Jan 27, 2026

Description

React.memo uses a shallow comparison, which isn't enough in this case.

Using welldone-software/why-did-you-render

I found our app home-screen content would update 12 times in one load with the wdyr message

"different objects that are equal by value".

This change adds a deep comparison, which when tested via patch-package, eliminated those re-renders.

Note: I tried to base this PR on the one that initially made these memo changes, hope it's okay :)

Screenshot

CleanShot 2026-01-27 at 19 59 52@2x

Note

Medium Risk
Changes React Native rendering behavior by switching React.memo to a deep comparator and tweaking state update semantics; could mask legitimate re-renders or add comparison overhead if misapplied.

Overview
Reduces unnecessary re-renders in the React Native SDK by switching Block and Blocks from default React.memo shallow comparison to a deep equality check via react-fast-compare.

Updates the React Native Blocks FlatList generation to pass extraData={builderContext} to ensure list items refresh when context changes, and adjusts flattenState to call rootSetState with a new object reference ({ ...target }) so React/RN reliably detects state updates.

Adds react-fast-compare as a dependency and includes a patch changeset for @builder.io/sdk-react-native.

Reviewed by Cursor Bugbot for commit 86699fe. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 27, 2026

🦋 Changeset detected

Latest commit: 86699fe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@builder.io/sdk-react-native Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jakequade-pc
Copy link
Copy Markdown
Author

jakequade-pc commented Jan 27, 2026

cc @samijaber @sidmohanty11 just for visibility 😊 thanks for your time!

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 30, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 86699fe

Command Status Duration Result
nx test @e2e/react-native-76-fabric ❌ Failed 7m View ↗
nx test @e2e/react-native-74 ❌ Failed 5m 59s View ↗
nx test @snippet/react ❌ Failed 4m View ↗
nx test @e2e/qwik-city ✅ Succeeded 8m 14s View ↗
nx test @e2e/nextjs-sdk-next-app ✅ Succeeded 7m 56s View ↗
nx test @e2e/angular-17 ✅ Succeeded 7m 27s View ↗
nx test @e2e/nuxt ✅ Succeeded 6m 32s View ↗
nx test @e2e/angular-17-ssr ✅ Succeeded 6m 19s View ↗
Additional runs (38) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2026-04-04 07:31:36 UTC

@sidmohanty11
Copy link
Copy Markdown
Contributor

thanks @jakequade-pc for the PR, looks good to me - tagging @midhunadarvin to take a look once on why the tests aren't running and help out

@midhunadarvin midhunadarvin self-assigned this Feb 4, 2026
@midhunadarvin
Copy link
Copy Markdown
Contributor

@jakequade-pc Could you rebase your branch with the main branch ? The e2e tests should run properly once you've rebased.

@jakequade-pc jakequade-pc force-pushed the perf-react-native-deep-memo-comparison branch from ad3738b to 77421c5 Compare February 4, 2026 22:00
@jakequade-pc
Copy link
Copy Markdown
Author

@midhunadarvin done! Thanks for your patience with this

@midhunadarvin
Copy link
Copy Markdown
Contributor

@jakequade-pc There are a couple of E2E test workflows failing :
https://github.com/BuilderIO/builder/actions/runs/21690062241/job/62576597925?pr=4253
https://github.com/BuilderIO/builder/actions/runs/21690062241/job/62576597914?pr=4253

Could you take a look at the failing test cases and try to resolve them ? Let me know if you need any additional help.

Comment thread packages/sdks/mitosis.config.cjs Outdated
@jakequade-pc
Copy link
Copy Markdown
Author

I've run the failing test suites locally and can confirm they pass. Again, I really appreciate the time, regardless of the outcome we land on!

Comment thread packages/sdks/src/functions/evaluate/helpers.ts
Comment thread packages/sdks/src/functions/evaluate/helpers.ts Outdated
@jakequade-pc jakequade-pc force-pushed the perf-react-native-deep-memo-comparison branch from 9a8553e to 567f4a0 Compare February 6, 2026 12:48
@jakequade-pc
Copy link
Copy Markdown
Author

jakequade-pc commented Feb 9, 2026

Thanks for your assistance with this one @midhunadarvin, should be good for re-test whenever suits 🙏

Edit: will revisit the failing svelte and angular tests.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread packages/sdks-tests/src/e2e-tests/large-reactive-state.spec.ts Outdated
- Use react-fast-compare for memo(Block, isEqual) and memo(Blocks, isEqual)
- Add extraData={builderContext} to FlatList for context change detection
- Fix flattenState to always mutate target before notifying rootSetState with a new object reference
@jakequade-pc jakequade-pc force-pushed the perf-react-native-deep-memo-comparison branch from 0a6d048 to 86699fe Compare April 4, 2026 06:09
@jakequade-pc
Copy link
Copy Markdown
Author

@midhunadarvin hello again :) are you able to run the E2E's on the branch again for me please? I've managed to get them passing locally.

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.

3 participants