Skip to content

Conversation

@CalixTang
Copy link
Contributor

@CalixTang CalixTang commented Oct 20, 2025

Summary:

Changelog: [Internal]

Modifies VirtualViewContainerStateExperimental to use an interval tree to store the container's VirtualViews. Interval tree's query allows us to lower the frequently-used updateModes() operation from O(n) to O(m + log n), where m is the number of VirtualViews in the hysteresis range. General layout changes incur a penalty due to the requirement of maintaining a balanced BST.

Performance Changes:

  • updateModes(): O(n) -> O(m + log n) (new algo)
  • updateMode(): O(1) -> O(1)
  • add VV: O(1) -> O(log n)
  • update VV: O(1) -> O(log n)
  • delete VV: O(1) -> O(log n)

We expect scrolling to be much more frequent than a total layout change/updating many of the elements in the container at once. However, the initial load of a page will take O(n log n) time rather than O(n) time.

We also include some bookkeeping sets for "old" hysteresis, prerender, and visible VVs. This will increase the memory footprint of VirtualViewContainerState by O(m).

Note

This diff only covers the Android version. iOS may follow after experimentation.

Reviewed By: lunaleaps

Differential Revision: D83783201

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 20, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 20, 2025

@CalixTang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D83783201.

Summary:
Introduces new React Native feature flag for VirtualViewContainerState versioning changes.

Follow up diffs will create classic and experimental versions of VirtualViewContainerState. This feature flag is meant to eventually be overridden with MetaConfig variables.

Differential Revision: D84569199
Summary: Removes unnecessary `debugLog` import in ReactVirtualViewExperimental and refactors the debug function

Differential Revision: D84608555
…Android]

Summary: Splits VirtualViewContainerState implementation into three parts: (1) an abstract parent class, (2) the "classic" version (existing version), and (3) the "experimental" version (new changes to be made). The experimental version is a copy of the classic version for now.

Differential Revision: D84569206
CalixTang added a commit to CalixTang/react-native that referenced this pull request Oct 20, 2025
…eModes optimization) (facebook#54213)

Summary:
Pull Request resolved: facebook#54213

## Changelog: [Internal]
Modifies `VirtualViewContainerStateExperimental` to use an interval tree to store the container's VirtualViews. Interval tree's query allows us to lower the frequently-used updateModes() operation from `O(n)` to `O(m + log n)`, where `m` is the number of VirtualViews in the hysteresis range. General layout changes incur a penalty due to the requirement of maintaining a balanced BST.

Performance Changes:
* updateModes(): `O(n) -> O(m + log n)` (new algo)
* updateMode(): `O(1) -> O(1)`
* add VV: `O(1) -> O(log n)`
* update VV: `O(1) -> O(log n)`
* delete VV: `O(1) -> O(log n)`

We expect scrolling to be much more frequent than a total layout change/updating many of the elements in the container at once. However, the initial load of a page will take `O(n log n)` time rather than `O(n)` time.

We also include some bookkeeping sets for "old" hysteresis, prerender, and visible VVs. This will increase the memory footprint of `VirtualViewContainerState` by `O(m)`.

More details are in https://docs.google.com/document/d/1Cmamx6fNfruoHLApX8tedqNVZsCEUyoBvQWpMvBsfcY/edit?tab=t.gqla6vu3231k.

### Note
This diff only covers the Android version. iOS may follow after experimentation.

Reviewed By: lunaleaps

Differential Revision: D83783201
CalixTang added a commit to CalixTang/react-native that referenced this pull request Oct 20, 2025
…eModes optimization) (facebook#54213)

Summary:
Pull Request resolved: facebook#54213

## Changelog: [Internal]
Modifies `VirtualViewContainerStateExperimental` to use an interval tree to store the container's VirtualViews. Interval tree's query allows us to lower the frequently-used updateModes() operation from `O(n)` to `O(m + log n)`, where `m` is the number of VirtualViews in the hysteresis range. General layout changes incur a penalty due to the requirement of maintaining a balanced BST.

Performance Changes:
* updateModes(): `O(n) -> O(m + log n)` (new algo)
* updateMode(): `O(1) -> O(1)`
* add VV: `O(1) -> O(log n)`
* update VV: `O(1) -> O(log n)`
* delete VV: `O(1) -> O(log n)`

We expect scrolling to be much more frequent than a total layout change/updating many of the elements in the container at once. However, the initial load of a page will take `O(n log n)` time rather than `O(n)` time.

We also include some bookkeeping sets for "old" hysteresis, prerender, and visible VVs. This will increase the memory footprint of `VirtualViewContainerState` by `O(m)`.

More details are in https://docs.google.com/document/d/1Cmamx6fNfruoHLApX8tedqNVZsCEUyoBvQWpMvBsfcY/edit?tab=t.gqla6vu3231k.

### Note
This diff only covers the Android version. iOS may follow after experimentation.

Reviewed By: lunaleaps

Differential Revision: D83783201
CalixTang added a commit to CalixTang/react-native that referenced this pull request Oct 20, 2025
…eModes optimization) (facebook#54213)

Summary:
Pull Request resolved: facebook#54213

## Changelog: [Internal]
Modifies `VirtualViewContainerStateExperimental` to use an interval tree to store the container's VirtualViews. Interval tree's query allows us to lower the frequently-used updateModes() operation from `O(n)` to `O(m + log n)`, where `m` is the number of VirtualViews in the hysteresis range. General layout changes incur a penalty due to the requirement of maintaining a balanced BST.

Performance Changes:
* updateModes(): `O(n) -> O(m + log n)` (new algo)
* updateMode(): `O(1) -> O(1)`
* add VV: `O(1) -> O(log n)`
* update VV: `O(1) -> O(log n)`
* delete VV: `O(1) -> O(log n)`

We expect scrolling to be much more frequent than a total layout change/updating many of the elements in the container at once. However, the initial load of a page will take `O(n log n)` time rather than `O(n)` time.

We also include some bookkeeping sets for "old" hysteresis, prerender, and visible VVs. This will increase the memory footprint of `VirtualViewContainerState` by `O(m)`.

More details are in https://docs.google.com/document/d/1Cmamx6fNfruoHLApX8tedqNVZsCEUyoBvQWpMvBsfcY/edit?tab=t.gqla6vu3231k.

### Note
This diff only covers the Android version. iOS may follow after experimentation.

Reviewed By: lunaleaps

Differential Revision: D83783201
…eModes optimization) (facebook#54213)

Summary:
Pull Request resolved: facebook#54213

## Changelog: [Internal]
Modifies `VirtualViewContainerStateExperimental` to use an interval tree to store the container's VirtualViews. Interval tree's query allows us to lower the frequently-used updateModes() operation from `O(n)` to `O(m + log n)`, where `m` is the number of VirtualViews in the hysteresis range. General layout changes incur a penalty due to the requirement of maintaining a balanced BST.

Performance Changes:
* updateModes(): `O(n) -> O(m + log n)` (new algo)
* updateMode(): `O(1) -> O(1)`
* add VV: `O(1) -> O(log n)`
* update VV: `O(1) -> O(log n)`
* delete VV: `O(1) -> O(log n)`

We expect scrolling to be much more frequent than a total layout change/updating many of the elements in the container at once. However, the initial load of a page will take `O(n log n)` time rather than `O(n)` time.

We also include some bookkeeping sets for "old" hysteresis, prerender, and visible VVs. This will increase the memory footprint of `VirtualViewContainerState` by `O(m)`.

More details are in https://docs.google.com/document/d/1Cmamx6fNfruoHLApX8tedqNVZsCEUyoBvQWpMvBsfcY/edit?tab=t.gqla6vu3231k.

### Note
This diff only covers the Android version. iOS may follow after experimentation.

Reviewed By: lunaleaps

Differential Revision: D83783201
@meta-codesync
Copy link

meta-codesync bot commented Oct 21, 2025

This pull request has been merged in 328d07a.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants