Skip to content

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

Open
jakequade-pc wants to merge 3 commits 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 3 commits intoBuilderIO:mainfrom
jakequade-pc:perf-react-native-deep-memo-comparison

Conversation

@jakequade-pc
Copy link

@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 render memoization and state update propagation in React Native paths, which can affect update behavior and performance; also adds a new runtime dependency (react-fast-compare).

Overview
Reduces unnecessary React Native re-renders by switching generated Block and Blocks components from memo(Component) to memo(Component, isEqual) using react-fast-compare, and wiring FlatList extraData to builderContext so list items refresh when context changes.

Fixes reactive state updates in flattenState by ensuring rootSetState receives a new object reference ({ ...target }) on nested and top-level writes, improving change detection in React/RN. Adds react-fast-compare as a dependency and includes a patch changeset; also adds a debug console.log(page.content()) to the large state e2e test.

Written by Cursor Bugbot for commit 0a6d048. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

🦋 Changeset detected

Latest commit: 0a6d048

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
Author

jakequade-pc commented Jan 27, 2026

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

@nx-cloud
Copy link

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 567f4a0

Command Status Duration Result
nx test @e2e/angular-17 ❌ Failed 5m 24s View ↗
nx test @e2e/angular-19-ssr ❌ Failed 4m 7s View ↗
nx test @e2e/svelte ❌ Failed 4m 17s View ↗
nx test @e2e/sveltekit ❌ Failed 4m 9s View ↗
nx test @e2e/angular-17-ssr ❌ Failed 4m 2s View ↗
nx test @builder.io/sdks ❌ Failed 5s View ↗
nx typecheck @builder.io/sdks ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-09 10:11:09 UTC

@sidmohanty11
Copy link
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
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
Author

@midhunadarvin done! Thanks for your patience with this

@midhunadarvin
Copy link
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.

@jakequade-pc
Copy link
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!

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

Using [welldone-software/why-did-you-render](https://github.com/welldone-software/why-did-you-render)

I found our homepage 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.
@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
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

@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.

await expect(page.getByText('0', { exact: true })).toBeVisible();

// log page contents
console.log(await page.content());
Copy link

Choose a reason for hiding this comment

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

Debug console.log accidentally left in test file

Low Severity

A console.log(await page.content()) statement was added to the maintains reactivity with large state test. This dumps the entire page HTML to the test output on every run, which is clearly leftover debugging code unrelated to the PR's purpose of adding deep memo comparison.

Fix in Cursor Fix in Web

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

Comments