Prism's RegionManager view switching performance

倾然丶 夕夏残阳落幕 提交于 2020-01-23 02:01:29

问题


I'm performance profiling a WPF application written using the PRISM library. Navigating from one view to another view is particulary slow in this application, especially when navigating away from a "heavy" view. Note that:

  • views are cached and not re-constructed when navigating back & forth
    (a consequence of PRISM keeping all views in the SingleActiveRegion)
  • I understand that constructing a view can be slow the first time due to xaml parsing, JIT'ing, .. BUT this question is about navigation remaining slow, even AFTER opening a view for the first time

Using the PRISM library, regions are generally implemented on a ContentControl, like:

<ContentControl regions:RegionManager.RegionName="MAIN" />

As a consequence, switching a view in the MAIN region will update the "Content" of this ContentControl (as can be seen from the source code). Setting & switching UI elements as the "Content" of a ContentControl has performance side effects (see this blogpost).

To overcome this behavior, I implemented a custom RegionAdapterBase (CachingGridRegionAdapter.cs) for a Grid, which basically adds all views being navigated as Children, and hides all non-active views.

The performance gains are tremendous; navigating from one view to another view is instant now. Question: are there any downsides to this approach?

  • memory-wise, I don't see an issue since all views were kept in memory by PRISM anyway
  • is there a downside to having a big visual tree, with many parts having Visibility = Collapsed?


If there are any other ways to overcome this problem, please let me know.


Thanks for your time,
Koen

来源:https://stackoverflow.com/questions/41937963/prisms-regionmanager-view-switching-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!