The reason behind slow performance in WPF

前端 未结 3 1667
离开以前
离开以前 2020-12-14 04:42

I\'m creating a large number of texts in WPF using DrawText and then adding them to a single Canvas.

I need to redraw the screen in each <

3条回答
  •  死守一世寂寞
    2020-12-14 05:01

    @Vahid: the WPF system is using [retained graphics]. What you eventually should do, is devise a system where you only send "what has changed compared to previous frame" - nothing more, nothing less, you should not be creating new objects at all. It's not about "creating objects takes zero seconds", it's about how it affects rendering and the time. It's about letting the WPF do it's job using caching.

    Sending new objects to the GPU for rendering=slow. Sending only updates to the GPU which tells what objects moved=fast.

    Also, it's possible to create Visuals in an arbitrary thread to improve the performance (Multithreaded UI: HostVisual - Dwayne Need). That all said, if your project is pretty complex in 3D wise - there's good chance that WPF won't just cut it. Using DirectX.. directly, is much, much, more performant!

    Some of the articles I suggest you to read & understand:

    [Writing More Efficient ItemsControls - Charles Petzold] - understand the process how one achieves better drawing rate in WPF.

    As for why your UI is lagging, Dan answer seems to be spot on. If you are trying to render more than WPF can handle, the input system will suffer.

提交回复
热议问题