Friday, June 3, 2011

Displaying Buffer Data in a .NET Application

Hi Everyone,


Recently I bought a new computer. It isn't high end but enough for the things I regularly do.
I got I5 760 2.8Ghz CPU with 4Gb of memory (1333Mhz) and ~2Tb of hard disk space.


Why am I telling you this? Because today I am going to tackle a simple problem: Loading a buffer into a text editing element. 
The setup is as follows: I have created a 8Mb file which contains the letter "A" 2^23 times (basically it is a huge line of As :)) and created some sample programs which contain only a text editing control and a button which loads the file into the control. All I do is click the button.


Legend:
Time - The time it took between pressing the button and the time the control is finished loading (if the control supports virtualization I scrolled all the way down).
Time to show data - The time it took beteen pressing the button and the time something was visible for user interaction (this is also the time until the UI became responsive).
Memory consumption - The amount of private bytes used by the application after the control is fully loaded.
Is it possible to work - Was it possible to interact with the loaded data in an acceptable manner.



  1. WPF TextBox (No text wrapping) - 
    1. Time - 11min 50sec
    2. Time to show data - less than 1 second
    3. Memory consumption - 930Mb
    4. Is it possible to work - Not really, I can interact with the TextBox but it is hard to do something.
    5. Although I set the TextBox to no wrapping the text was wrapped.
  2. WPF TextBox (with text wrapping) -
    1. Time - 15 sec
    2. Time to show data - less than 1 second
    3. Memory consumption - 330Mb
    4. Is it possible to work - Yes, the UI was quite responsive
  3. WPF RichTextBox  
    1. Time - 17 sec
    2. Time to show data - 17 sec
    3. Memory consumption - 440Mb
    4. Is it possible to work - Not really, everything I did made the UI not respond for a while
  4. Winforms TextBox  
    1. Time - I stopped waiting after 25 minutes
Now onto more advanced editors
  1. Avalon Edit May 2011 (no text wrapping)
    1. Time - 3 min 5 sec
    2. Time to show data - 3 min 5 sec
    3. Memory consumption - 650Mb
    4. Is it possible to work - Not really, everything I did made the UI not respond for a while
  2. Avalon Edit May 2011 (with text wrapping)
    1. Time - 3 min 5 sec
    2. Time to show data - 3 min 5 sec
    3. Memory consumption - 650Mb
    4. Is it possible to work - Not really, everything I did made the UI not respond for a while
  3. ICSharpCode.TextEditor
    1. Time - 4 sec
    2. Time to show data - 4 sec
    3. Memory consumption - 60Mb
    4. Is it possible to work - Not really. It was very slow although somewhat responsive
I would like to note that the above editors are very advanced editors which were not designed for the purpose of loading buffers. These editors excel in editing and displaying code.

Some well known editors
  1. Notepad (Windows 7)
    1. Time - 1 sec
    2. Time to show data - 1 sec
    3. Memory consumption - 20Mb
    4. Is it possible to work - Yes, the UI was completly responsive as if you are editing a 10 byte file
  2. Notepad++ 5.8.7
    1. Time - 1 sec
    2. Time to show data - 1 sec
    3. Memory consumption - 100Mb
    4. Is it possible to work - No, it hung after I scrolled around
  3. Visual Studio 2010 Ultimate SP1
    1. Time - 12 sec
    2. Time to show data - 12 sec
    3. Memory consumption - 220Mb 
    4. Is it possible to work - Yes, the UI was slow but still possible to work with
Conclusion
It seems that the default editors of .NET have problems with handling this case. Even when they are successful in loading the file, the memory consumption is quite large and the UI is not responsive. It is also obvious that Microsoft has solved this problem internally because their editors handle this case without a problem.

As usual please feel free to comment (especially if you know of a good editing control which can handle this case).

Thanks for reading,
Boris.

No comments:

Post a Comment