-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Performance degradation when navigating to a page and going back several times #12930
Description
Description
Each time a page navigates to another created by a dependency service as a result of a call to Shell.Current.GoToAsync a new instance of that page is created and the time to create and/or navigate to that page is incrementally extended.
The attached sample project demonstrates this behavior.
The project is standard MAUI template app with a MainPage and an additional NewPage with some controls on it to speed up the effect of delaying. The idea is that the MainPage navigates to the NewPage and then the NewPage returns back to MainPage in a loop and the loading time of the NewPage is measured and displayed. This loading time get gradually increased.
Timers have been added to MainPage and NewPage. When the timer event occurs in the MainPage the current time is taken and navigation to the NewPage is initiated. When NewPage finishes loading, it displays how long it took to load. The timer in NewPage then triggers a "back" action by executing Shell.Current.GoToAsync(".."). The MainPage timer starts again and the loop continues infinitely.
You can notice that the load time (in milliseconds) presented in NewPage increases with each iteration. After 20-30 iterations, the loading time becomes a few seconds and continues to grow.
This behavior is observed on all three tested platforms – iOS, Android and Windows.
No latency increase is observed when NewPage is added to the dependency service as a AddSingleton<NewPage>() and progressively increasing latency is experienced when added as a AddTransient<NewPage>().
Steps to Reproduce
Please run the attached project and click the button "Start the loop" then observe the number in the page that shows up.
Link to public reproduction project repository
https://github.com/gkamenov/MauiBug
Version with bug
7.0 (current)
Last version that worked well
7.0 (current)
Affected platforms
iOS, Android, Windows
Affected platform versions
iOS 14.2 and up, Android 8 and up, Windows build 22621.1105
Did you find any workaround?
No workaround so far.
Relevant log output
No response