Bug Report T296163
Visible to All Users

CPU usage is getting high when typing fast in TextEdit due to a lot of LayoutControls with ScrollBars=Auto

created 9 years ago (modified 9 years ago)

Hi,

We encounter an issue of CPU usage getting high when typing fast in a TextEdit. Please open the attached sample and reproduce the situation through the following steps.

  1. Compile and run the sample solution
  2. Open 'Windows Task Manager ' | 'Performance' tab | 'Resource Monitor' | 'CPU' tab
  3. Check 'WpfApplication.vshost.exe' in the processes list
  4. Try to 'fast' type 'different' character s in the TextEdit (Do not press a single key)
  5. The CPU usage of  'WpfApplication.vshost.exe' reach about 15%
  6. Close program
  7. Modify file '…\PerformanceIssue\WpfApplication\pageImageGallery.xaml' and remove all LayoutControl
  8. Repeat step 1 to step 5, the CPU usage is below 5%

Even though we do not use LayoutControl in an ItemControl, the CPU usage is still affected (CPU usage is around 10%).

Why does a 'user control's LayoutControl' affect the efficiency of a 'TextEdit in the main window'?
Is it a bug or how can we avoid this problem ?

We have placed a lot of LayoutControl in our application and encounter the slow response problem. Please assist resolving the issue.

Thank you in advanced.
Chandler

Show previous comments (5)
CC CC
Chandler Cheng 9 years ago

    Hi Alexander,
    I did not try to count a number of LayoutControl in our program. The LayoutControl is quite useful and we almost use LayoutControl instead of Grid/Stack panel in our program. As I understand, I do not think the sample code is in a abnormal usage. I just tried to make the sample code clean and addressed the issue. I have made another sample code in the attached. It should be more practical as you wish. CPU usage of 'PerformanceIssue04.zip' still can reach 15% in my computer. You may uncomment a 'Grid/StackPanel' version block in MainWindow.xaml and you will examine a 5% CPU usage (in my computer).
    It is obvious that all LayoutControl are continuously calculating/rendering when we are typing in a TextBox. Is it expected by DevExpress? If so, are there any ways that we could stop LayoutControl calculating since the layout has been well arranged at beginning.
    Thank you in advanced.
    Chandler

    CC CC
    Chandler Cheng 9 years ago

      All we need is, LayoutControl should not occupy the CPU usage when we typing in a TextBox which is out of sight from LayoutControl.
      Chandler

      Alex Chuev (DevExpress) 9 years ago

        Hi Chandler,

        I will check with our developers to see if LayoutControl performs any calculations when you are typing in the TextBox and get back to you.

        Thanks,
        Alex

        Answers approved by DevExpress Support

        created 9 years ago (modified 9 years ago)

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

        Additional information:

        Starting with version 15.1.8, LayoutControl will not load the content of its scroll bars if they don't need to be displayed.

          created 9 years ago (modified 9 years ago)

          Chandler,

          After double-checking, I can confirm that LayoutControl does not perform any time-consuming calculations when a user types in the editor. However, as you probably know, one of the factors that significantly affects performance in a WPF application is the number of visual elements. By default, every LayoutControl contains scroll bars inside. Scroll bars are fairly heavy, and with them the total number of visual elements in your application reaches 8000 (compared to 3400 when Grids/StackPanels are used). If you disable scroll bars for your LayoutControls by setting the ScrollBars property to 'None', the number of visual elements will drop to 2400 and the application will be as responsive as with Grids/StackPanels.

          XAML
          <Application.Resources> <Style TargetType="dxlc:LayoutControl"> <Setter Property="ScrollBars" Value="None" /> </Style> </Application.Resources>

          I've modified your sample project to demonstrate this.

          Thanks,
          Alex

            Show previous comments (2)
            Alex Chuev (DevExpress) 9 years ago

              Hi Chandler,

              Of course, it's not only the number of visual elements that matters. For example, certain elements may be bound to routed commands that are still passed to your UserControl, even though you are typing in a distant TextBox. To check this, try replacing TextBoxes in Ilya's sample with Buttons bound to the PageUp command:

              XAML
              <Button Command="{x:Static ScrollBar.PageUpCommand}" />

              There is no generic way of 'measuring' the complexity of a control, except for testing it in your particular scenario. There are also recommendations that are specific for a certain control. For example, if you are using GridControl in your application, make sure to turn on the Optimized Mode to significantly reduce the complexity of cell/row elements.

              Thanks,
              Alex

              CC CC
              Chandler Cheng 9 years ago

                Hi Alex,
                Thanks again for providing the requested information and clues. I will continue on optimizing the responsiveness of our program.
                Thank you.
                Chandler

                Alex Chuev (DevExpress) 9 years ago

                  My pleasure, Chandler.

                  Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                  Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.