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

Data virtualization is no longer supported after preview4 #11641

Closed
jim-jiang-github opened this issue Jun 4, 2023 · 19 comments · Fixed by #11752
Closed

Data virtualization is no longer supported after preview4 #11641

jim-jiang-github opened this issue Jun 4, 2023 · 19 comments · Fixed by #11752
Assignees
Labels

Comments

@jim-jiang-github
Copy link

jim-jiang-github commented Jun 4, 2023

Describe the bug
It seems that data virtualization is no longer supported after preview4? Similar to using the IList interface to implement data virtualization in Wpf. I wrote a demo to implement data virtualization and display very, very, very large amounts of data.
Is there a new way to implement the function of data virtualization after preview4?
To Reproduce
Mini repo
data_virtualization.zip

Expected behavior
Can support data virtualization in preview7
Screenshots
image

IList Can support in preview4 like this:

bandicam.2023-06-04.13-40-28-606.mp4

Desktop (please complete the following information):

  • OS: [e.g. Windows, Mac, Linux (State distribution)]
  • Version [e.g. 0.10.0-rc1 or 0.9.12]

Additional context
Add any other context about the problem here.

@maxkatz6
Copy link
Member

maxkatz6 commented Jun 4, 2023

I am not sure if hack with int.MaxValue length is was intended to be supported.
More typical data virtualization can be implemented with handling scrolling events and adding more items when scroll is reaching specific point.
Also, you have not mentioned what exactly is happening on rc1, but I suppose avalonia just can't handle this int.MaxValue.
cc @grokys

@jim-jiang-github
Copy link
Author

jim-jiang-github commented Jun 4, 2023

I am not sure if hack with int.MaxValue length is was intended to be supported. More typical data virtualization can be implemented with handling scrolling events and adding more items when scroll is reaching specific point. Also, you have not mentioned what exactly is happening on rc1, but I suppose avalonia just can't handle this int.MaxValue. cc @grokys

We don't need int. MaxValue so much, we only need to give a larger data to find that there is a big difference between preview4 and later versions. In preview4, Listbox will only get the data displayed on the current page from IList, and then in the preview4 version No matter how much data Listbox currently displays, it will get all the data of IList. You can see the demo I submitted, which has examples of two versions.
data_virtualization.zip

@jim-jiang-github
Copy link
Author

I am not sure if hack with int.MaxValue length is was intended to be supported. More typical data virtualization can be implemented with handling scrolling events and adding more items when scroll is reaching specific point. Also, you have not mentioned what exactly is happening on rc1, but I suppose avalonia just can't handle this int.MaxValue. cc @grokys

To add, there is already a problem with the preview7 version

@jim-jiang-github
Copy link
Author

Listbox virtualization seems to fail after preview4???

@rabbitism
Copy link
Contributor

rabbitism commented Jun 4, 2023

From what I observed, Listbox is obviously virtualized, no matter how many items in the collection, the ListBoxItem in logic tree remains the same. But virtualizing stackpanel is trying to realize all containers in memory. But virtualizing stack panel is trying to calculate all snap points. Memory is consumed by these snap points.

image

@maxkatz6
Copy link
Member

maxkatz6 commented Jun 4, 2023

@emmauss I think knowing all items count shouldn't be required for uniform snap points.

@emmauss
Copy link
Contributor

emmauss commented Jun 4, 2023

VirtualizingStackPanel doesn't use the items count to compute both regular snap points, only irregular snappoints require items. By default, snappoints are irregular. If they are certain all items are uniform, they would have to set either AreVerticalSnapPointsRegular or AreHorizontalSnapPointsRegular to true

@rabbitism
Copy link
Contributor

rabbitism commented Jun 4, 2023

@emmauss I tried to do so but then items are misplaced. Offset errors are accumulated.

image

@emmauss
Copy link
Contributor

emmauss commented Jun 4, 2023

@emmauss I tried to do so but then items are misplaced. Offset errors are accumulated.

image

That's most likely an error in realization. @grokys may have some insight into this.

@grokys
Copy link
Member

grokys commented Jun 4, 2023

This is actually due to the new renderer which uses float precision. If you look at the position of the items in DevTools, they're laid out at the correct position because the layout system uses double precision. However because our compositing renderer is based on Windows.UI.Composition which uses float precision, our renderer also uses float and for good technical reasons I believe. If you try something similar on UWP/WinUI you will also see a similar problem.

I think we may need a separate virtualizing panel for large lists which uses logical non-smooth scrolling so that we don't hit this issue, or maybe we can switch to double precision in the renderer - @kekekeks would have thoughts on that.

(As a clarification - this is a response to the "items are misplaced" part of this issue, not the data virtualization part)

@grokys
Copy link
Member

grokys commented Jun 4, 2023

Ok, after discussing this with @kekekeks we're going to see if we can make the renderer work with double precision before 11.0 final.

@jim-jiang-github
Copy link
Author

Is there any workground that can solve this problem in rc1 version? I hope to display a large amount of data in the listbox. The current estimated number is 1000w pieces of data.

@timunie
Copy link
Contributor

timunie commented Jun 5, 2023

@jim-jiang-github I think the "easiest" workaround for now is pagination in the VM. May not be most convinient, but the fix we have in mind is not that straight forward afaik.

for example: https://github.com/reactivemarbles/DynamicData#virtualisation

@hez2010
Copy link
Contributor

hez2010 commented Jun 5, 2023

Windows.UI.Composition which uses float precision

Some GPUs don't support double precision at all and I believe this is an important reason why W.UI.C chose float precision.

@grokys
Copy link
Member

grokys commented Jun 11, 2023

@emmauss regarding the data virtualization, it's not great default behavior that the default value for AreVerticalSnapPointsRegular causes all items to be enumerated when the ItemsControl is shown. IIRC this setting is taken from UWP, does the same thing happen there?

@grokys grokys added this to the 11.0 milestone Jun 11, 2023
@grokys grokys removed this from the 11.0 milestone Jun 11, 2023
@emmauss
Copy link
Contributor

emmauss commented Jun 11, 2023

@emmauss regarding the data virtualization, it's not great default behavior that the default value for AreVerticalSnapPointsRegular causes all items to be enumerated when the ItemsControl is shown. IIRC this setting is taken from UWP, does the same thing happen there?

WinUI have both AreHorizontalSnapPointsRegular and AreVerticalSnapPointsRegular return false for StackPanel and VirtualizingStackPanel. The implementation for both properties and the snappoints methods are not available as the source isn't public.

@Developer-Alexander
Copy link

This is actually due to the new renderer which uses float precision. If you look at the position of the items in DevTools, they're laid out at the correct position because the layout system uses double precision. However because our compositing renderer is based on Windows.UI.Composition which uses float precision, our renderer also uses float and for good technical reasons I believe. If you try something similar on UWP/WinUI you will also see a similar problem.

I think we may need a separate virtualizing panel for large lists which uses logical non-smooth scrolling so that we don't hit this issue, or maybe we can switch to double precision in the renderer - @kekekeks would have thoughts on that.

(As a clarification - this is a response to the "items are misplaced" part of this issue, not the data virtualization part)

With how many items the issue becomes visible?

@kekekeks
Copy link
Member

kekekeks commented Jun 12, 2023

Some GPUs don't support double precision at all and I believe this is an important reason why W.UI.C chose float precision.

It's not about precision supported by GPU, it's about calculations where values cancel each other out. The most simple case would be:

  <ScrollViewer>
    <StackPanel>
      <Button Margin="0 1000000000 0 0">0</Button>
      <Button>1</Button>
    </StackPanel>
  </ScrollViewer>

So when the ScrollViewer is completely scrolled down, the StackPanel would have a negative Y offset of mostly the same value as the button margin, so the final offset from the window origin would be quite small. However due to the loss of precision during the final offset calculation the buttons would appear overlayed.
The same would happen with double, however it's way more precise (2⁵³ vs 2²³).

With how many items the issue becomes visible?

Assuming the offsets are integers and 96DPI, the loss of precision starts at 2²³ (8388608) pixels. It takes more for it to become noticeable.

@kekekeks
Copy link
Member

You can see a similar issue with web browsers, e. g.

<div>
  <div style="margin-top: 57000000px; width: 100px; height: 10px; background:red" ></div>
  <div style="margin-top: 10px; width: 100px; height: 10px; background:blue" ></div>
</div>

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 a pull request may close this issue.

9 participants