Skip to content

Conversation

@wangfeihang
Copy link
Contributor

Description:

This PR optimizes the scrolling jank issue of the TableView component when the number of rows exceeds 250,000.

Root Cause:

The _updateFirstAndLastVisibleCell method in RenderTableViewport uses linear for-loop traversal on _columnMetrics and _rowMetrics to locate the visible boundary cells: _firstNonPinnedRow, _lastNonPinnedRow, _firstNonPinnedColumn, and _lastNonPinnedColumn. When the number of rows/columns is extremely large (e.g., >250k rows), this linear traversal causes significant main-thread blocking and scrolling jank.

Solution:

Replace the linear for-loop with binary search algorithm to find the visible boundary cells (_firstNonPinnedRow, _lastNonPinnedRow, _firstNonPinnedColumn, _lastNonPinnedColumn). Binary search reduces the time complexity from O(n) to O(log n), effectively optimizing the scrolling jank issue under large data volumes.

Fixes: #138271

Video performance comparison

before:
https://github.com/user-attachments/assets/ca5b8821-4bdb-411f-bb2c-63998ac7c0d9

after:
https://github.com/user-attachments/assets/ebbf96d9-9e04-4ede-ae79-cd433885d3ab

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

@wangfeihang wangfeihang requested a review from Piinks as a code owner January 7, 2026 07:55
@github-actions github-actions bot added p: two_dimensional_scrollables Issues pertaining to the two_dimensional_scrollables package triage-framework Should be looked at in framework triage labels Jan 7, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant performance optimization for TableView when dealing with a large number of rows. The linear search for visible cells has been replaced with a more efficient binary search, which will reduce scrolling jank. The implementation of the binary search is sound and new tests have been added to ensure correctness. My feedback includes a few suggestions related to repository contribution guidelines for the CHANGELOG.md and pubspec.yaml files, as well as a minor refactoring opportunity in the new test to improve maintainability.

@wangfeihang wangfeihang requested a review from Piinks January 8, 2026 04:44
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Ah thank you thank you! This LGTM. I will seek a second stamp so we can get this in.

@wangfeihang wangfeihang requested a review from chunhtai January 17, 2026 09:40
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 21, 2026
@auto-submit auto-submit bot merged commit e6955be into flutter:main Jan 21, 2026
80 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 22, 2026
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Jan 22, 2026
flutter/packages@d80c60e...9010299

2026-01-21 jhy03261997@gmail.com [batch-release] Step2 : Publish
packages from the release branch (flutter/packages#10459)
2026-01-21 dpxhfxywang@163.com [two_dimensional_scrollables] optimizes
tableview janks with >250k rows (flutter/packages#10738)
2026-01-21 magder@google.com [url_launcher_ios] Migrate XCTest to Swift
Testing (flutter/packages#10780)
2026-01-21 edpizzi@gmail.com [in_app_purchase] Fix an issue causing
StoreKit 2 transactions remain unfinished (flutter/packages#10656)
2026-01-21 stuartmorgan@google.com [google_maps_flutter] Restructure iOS
to prep for SwiftPM (flutter/packages#10839)
2026-01-21 jhy03261997@gmail.com [batch-release] Step3: Adds github
action to create a PR to sync changes on the go_router release branch
back to the main branch (flutter/packages#10393)
2026-01-21 nateshmbhat1@gmail.com feat(ios): add audio track selection
support for AVFoundation (flutter/packages#10313)
2026-01-21 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump androidx.core:core from 1.13.1 to 1.17.0 in
/packages/image_picker/image_picker_android/android
(flutter/packages#10504)
2026-01-21 38853913+AlexDochioiu@users.noreply.github.com
[vector_graphics_compiler] Fix rgb/rgba color parsing to support modern
CSS syntax (flutter/packages#10538)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: two_dimensional_scrollables Issues pertaining to the two_dimensional_scrollables package triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tableview widget janks execessively with >250k rows

3 participants