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

Navigation and render performance is slow #2032

Closed
asierpn opened this issue Feb 26, 2020 · 14 comments
Closed

Navigation and render performance is slow #2032

asierpn opened this issue Feb 26, 2020 · 14 comments
Labels

Comments

@asierpn
Copy link

asierpn commented Feb 26, 2020

Describe the bug
In our case we are using UWP for a LOB app and we have found big performance issues in two common scenarios:

  1. We need to put a lot of data in some views, so we use use datagrid inside pivot or tab controls, this generates big visual trees of more than 5000 items which are hard to reduce more. The first load of the visual tree or when you switch from one tab to another is not smooth.
  2. Something similar happens with frame cache, we have it enabled so the state of our list views is keeped when you return from it's associated form, but if the page cached has a big visual tree the navigation when you go back is not smooth and hangs for a while. Moreover we notice a performance degradation when using the frame cache and you have navigated to a big number of views.

Steps to reproduce the bug

  1. Download this sample app made using DataGrid from Windows Community Toolkit:
    App1.zip
  2. Execute the app, the first datagrid takes a lot of time to be drawn
  3. Switch tabs, the first time it takes a lot of time to be drawn, the next times it switches faster but there is freezing.
  4. Navigate to second page, the same happens here, the first time it needs a lot of time to be drawn, the next times it is shown faster (it's cached) but there is freezing.

These issues are less noticeable if you use a powerfull machine, but with less power it becomes unusable (try it with a core i3 or i5 processor of a few years).

Expected behavior
A quick render of pages with 5000 items or more, and a smooth transition between tabs and pages, because this scenario is very common in LOB apps.

Version Info
No matter which package you are using, we are suffering this issue from the early versions of UWP.

NuGet package version: 2.3.200213001

Windows 10 version Saw the problem?
Insider Build (xxxxx) Yes
November 2019 Update (18363) Yes
May 2019 Update (18362) Yes
October 2018 Update (17763) Yes
April 2018 Update (17134) Yes
Fall Creators Update (16299) Yes
Creators Update (15063) Yes
@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Feb 26, 2020
@StephenLPeters
Copy link
Contributor

Are your issues exclusive to datagrid? If so it might be more appropriate to open an issue on their repository: https://github.com/windows-toolkit/WindowsCommunityToolkit. Performance could likely be impoved on that control. My understanding is that it was a rather targeted addition and could maybe use some further optimization. @RBrid for FYI.

@StephenLPeters StephenLPeters added area-DataGrid DataGrid control team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Feb 26, 2020
@asierpn
Copy link
Author

asierpn commented Feb 27, 2020

No, the issue happens when you have a page with a big visual tree, I've created the sample app using the DataGrid to show you easily the real scenario where we need to deal with big visual trees. If you change the DataGrid with a any other big visual tree you will get the same behavior.

@marcelwgn
Copy link
Contributor

Something you can do, to make navigation (feel) more smoothly, is to do expensive operations, such as setting ItemsSource of the datagrid, in the Loaded event. Anything you do in the constructor of a page, will be executed before the navigation takes place, however anything done in Loaded happens after the navigation to the page has taken place, making switching pages feel more smoothly.

@asierpn
Copy link
Author

asierpn commented Aug 10, 2020

@chingucoding we use a similar approach to improve the feel when navigating to a new created page, but this issue happens when you navigate to a cached page with a large visual tree, in this case navigation freezes despite of all controls of the page are loaded.

@Noemata
Copy link

Noemata commented Mar 31, 2021

@asierpn , NavigationView seems to somehow disable this.NavigationCacheMode = NavigationCacheMode.Enabled. We haven't had time to look into this in detail so I haven't filed an issue. We've been using Pivot in place of NavigationView because of this problem. Your problem may be something completely different. We're finding caching of UWP pages to be extremely effective for our purposes using the above caching flag. It's a very large app with huge data needs. Page transitions are instantaneous.

@Noemata
Copy link

Noemata commented Mar 31, 2021

@asierpn , took a look at your code, looks like NavigationCacheMode.Enabled will become your very good friend.

@asierpn
Copy link
Author

asierpn commented Mar 31, 2021

@Noemata We use a Frame control in the MainPage of the app to navigate to all Pages, NavigationCacheMode is enabled, but our app freezes after several navigation operations, this is very noticeable in low powered machines. It seems that it is related with the memory leaks, if you try the sample project I attached in this issue and navigates from Page1 to Page2 and back repeatedly you will notice that memory doesn't stop growing and after some time the UI starts freezing.

@Noemata
Copy link

Noemata commented Mar 31, 2021

@asierpn, I've tweaked your sample. I think I know what's happening. Look at how I set the cache size in MainPage. I get the expected behavior with this sample when the cache size is set correctly. Caching works quite nicely when everything is configured to accommodate the needs of the app.

You could also pre-cache certain pages by doing a behind the scenes navigation to those pages if you want to hide the impact of a data load.

App1.zip

Please let me know if something isn't clear.

When cachesize is configured correctly, you will not see repeated "Page x not cached." messages in the debug output window. These should only appear once, when the page first loads.

@asierpn
Copy link
Author

asierpn commented Mar 31, 2021

@Noemata Thank you for your time trying to help us, we know how caching works, if you don't set it the Frame has a default CacheSize of 10, but this issue happens also disabling the cache, enabling the cache helps to reduce the issue, but after a long use time navigating to different pages the issue always happens. As I've commented it's easy to reproduce the issue with the official XAML Controls Gallery app.

@Noemata
Copy link

Noemata commented Mar 31, 2021

@asierpn , if you're not on a recent OS build, UWP leaks in a number of ways. On the OS build I'm running on, I'm not seeing the problem you see (19042.906). I throttled the sample I sent through a 2K navigations on a release build. No slow down or excessive memory growth.

I did switch to the latest nuget packages for my test. Also replaced the tabview with pivot. So it's possible the older libs/controls have issues.

@asierpn
Copy link
Author

asierpn commented Mar 31, 2021

@Noemata, it's strange, I'm also using a recent OS build (19042.867) and we see this issue in all computers inside and outside our organization, tomorrow I will record an screencast to show you it better.

@Noemata
Copy link

Noemata commented Mar 31, 2021

@asierpn , suggest you switch to newer libs. It's looking like that is where your problem is. Sorry, I should have qualified that I switched. I too had problems with older Toolkit builds. When I swapped out the toolkit, I lost the Tabview control, since that's now in WinUI. I assumed the entire problem you were having was with navigation. Looks like it's elsewhere. My bad.

@Noemata
Copy link

Noemata commented Mar 31, 2021

@asierpn , want to to be clear, I got it wrong. My corrections are here:

#4597

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants