Skip to content

Conversation

@everettbu
Copy link

Mirror of facebook/react#35370
Original author: romgrk


Summary

Considering that effects are only appended (the list of effects is never mutated in the middle), Array seems like a better fit because it has a better cache locality, and it creates less memory allocations so there's less pressure on the GC.

How did you test this change?

I have tested various benchmarks we have in Base UI and they've shown a fairly small but consistent improvement across the board. I've also spin up this benchmark that puts an extreme focus on effects to illustrate clearly the improvement. The average runtime is consistently lower, but interestingly the standard deviation is also consistently lower, which probably indicates that the garbage collector is doing less pauses (due to the fewer memory allocations).

Before:
image
After:
image

@greptile-apps
Copy link

greptile-apps bot commented Dec 16, 2025

Greptile Overview

Greptile Summary

Replaces circular linked list with array for storing effects in function components, improving cache locality and reducing GC pressure.

  • Changed FunctionComponentUpdateQueue.lastEffect (circular linked list) to effects (array)
  • Removed next field from Effect type definition
  • Simplified pushEffectImpl from circular linked list insertion to simple array push
  • Replaced do-while circular list traversal with standard for loop in effect commit functions
  • Maintains exact same iteration order (first-to-last insertion order)

Confidence Score: 5/5

  • This PR is safe to merge with no risk - clean performance optimization with behavior-preserving refactor
  • The refactor is a straightforward data structure change that preserves exact functional behavior while improving performance. The circular linked list traversal logic has been correctly converted to array iteration maintaining the same order. All references to the old structure have been properly updated, and the change reduces code complexity.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/react-reconciler/src/ReactFiberHooks.js 5/5 Refactored effect storage from circular linked list to array in FunctionComponentUpdateQueue, simplified pushEffectImpl to use array push, removed next field from Effect type
packages/react-reconciler/src/ReactFiberCommitEffects.js 5/5 Replaced circular linked list traversal (do-while) with standard array iteration (for loop) in commitHookEffectListMount and commitHookEffectListUnmount

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants