在什么情况下冻结WPF对象会极大地提高性能? [英] In what scenarios does freezing WPF objects benefit performance greatly?

查看:88
本文介绍了在什么情况下冻结WPF对象会极大地提高性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF中的许多类型都是从Freezable派生的.它提供了可变POCO对象的不变性,并且显然可以在某些情况下提高性能.

Many types in WPF derive from Freezable. It provides immutability to mutable POCO objects and, apparently, allows for improved performance in certain situations.

是否有人发现冻结其WPF应用程序中的对象可以大大提高性能?如果是这样,那么冻结时哪些项目的性能差异最大?

Has anyone found that freezing objects within their WPF application has greatly improved performance? If so, then which items gave the biggest performance difference when being frozen?

(请注意,我也发布了类似但又不同的问题)

(Note that I have posted a similar but different question too)

推荐答案

您可能对我使用Freezable的经历感兴趣:

You might be interested in my experiences with Freezable:

我曾经用muPdf编写了一个PDF查看器,它可以渲染位图,而我是使用WPF渲染的.可以极大地提高性能的是,我可以在后台线程上渲染页面位图,将其冻结,然后将其传递给UI线程. WPF不会复制图像以冻结它是很好的,但是能够在后台线程上完成所有这些准备工作对我来说是一个主要好处.

I once wrote a PDF viewer using muPdf which renders bitmaps, that I render with WPF. What helps performance greatly is that I can render the page bitmaps on a background thread, freeze them, and then pass them to the UI thread. It is nice that WPF does not copy the image to freeze it, but the ability to do all this preparation on a background thread was the key benefit for me.

据我了解,所有视觉效果都需要冻结,以便可以由WPF渲染线程安全地渲染.如果渲染大型未冻结的视觉效果,则在WPF渲染它们时,它们将被克隆为冻结的视觉效果.如果事先冻结静态位图,则WPF可以与渲染线程共享指针,而无需进行克隆.如果WPF不知道从上次渲染对象起是否更改了对象,则甚至可以重复复制未冻结的对象.冻结的对象消除了所有这些复制的需要.

From what I understand, all visuals need to be frozen so they can be safely rendered by the WPF render thread. If you render large unfrozen visuals, they will get cloned to frozen ones when WPF renders them. If you freeze your static bitmaps beforehand, WPF can just share the pointer with the render thread without cloning. Unfrozen objects may even get copied repeatedly if WPF is not aware wether the object is changed from the last time it was rendered. Frozen objects eliminate the need for all this copying.

这篇关于在什么情况下冻结WPF对象会极大地提高性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆