Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic row height offset bug #4

Merged
merged 1 commit into from
Jun 4, 2016

Conversation

KamranAsif
Copy link
Contributor

Description

Row offset calculation is dependent on a subset of previous row offsets. ScrollHelper's scrollTo or scrollBy functions calculate them correct. But you may update scrollPosition without triggering a scrollTo/scrollBy.

A simple way to test this is to scroll down a bunch, then scroll up to the first row and collapse it. See attached video.

This fix forces the sorts the rows before calculating their offsets.

This shouldn't hamper performance because visible rows should be small. It may be possible to speed this up using something like radix sort.

Motivation and Context

facebookarchive/fixed-data-table#405

How Has This Been Tested?

Tested locally but running dev site.
See video
for original repo steps.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.


//Row position calculation requires that rows are calculated in order
sortedRowsToRender.forEach((rowIndex) => {
rowPositions[rowIndex] = rowPositionGetter(rowIndex);
Copy link
Member

@wcjordan wcjordan Jun 3, 2016

Choose a reason for hiding this comment

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

Does this still suffer from the n*log(n) issue you mention here?
facebookarchive/fixed-data-table#405

Or is it only m*log(n) where m is the number of rows we render?

-- edit --
If we're just operating over the rows on screen I can't imagine m*log(n) would be very slow, but if it is we could optimize the rowPositionGetter method used for this case since I think we should be able to do it in m + log(n) time.
Rambling thoughts on that below.

Would it be possible to just run rowPositionGetter for the first row in the sorted range and then compute the rest by adding the result of getRowHeight to a sum here? That should give the performance increase I'm imagining.
We'd want to push the logic into scroll helper and have it return an array of rowPositions so it could also do the work of _updateRowHeight. Also we should be wary of off by one errors since I'm not 100% sure if row 2's position is row 1's position + row 1's height or row 1's position + row 2's height (probably the first case though).

We'll still see m*log(n) time from updating the PrefixIntervalTree when we first see row heights. It'd be great if we could batch those updates as well since the m rows being rendered probably share many of the same parent nodes in that tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No nLogN performance issue, I misread the code somewhere.

If m is the visible row count, we have m log m from the sort, and m log n from rowPositionGetter. The total complexity remains unchanged, since m > n.

I agree that we could manually iterate on the first position getter, reducing it to m + logN, but I think we should do that in a follow up review. I'm not imagining the priority for that is super high, plus its out of scope for this bug.

Copy link
Member

Choose a reason for hiding this comment

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

sgtm, it's not worth the added complexity unless we see a perf issue.

@wcjordan
Copy link
Member

wcjordan commented Jun 3, 2016

lgtm once a plan for the perf concern is in place

@KamranAsif KamranAsif merged commit b4394d1 into schrodinger:master Jun 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants