sharkal | 19 Mar 2012 16:11
Favicon
Gravatar

Too slow performance on RichTextBox?

Hi,

i am listening on some udp ports at the same time, where messages will be
received asynchronous in average ~ each 5-10ms. These messages i will write
into a logfile at a lower level ( own thread)  and also display the message
in the GUI in a RichTextBox with a certain color. For this, i add the
messages in a list  and a backgroundworker will flush the list after a
certain period into the RichTextBox:
                rtxtLogMessages.SuspendLayout();
                foreach (var log in logMessages)
                {
                    rtxtLogMessages.AppendText(log.Value + "\n");
                } 
                rtxtLogMessages.ResumeLayout(true);

*The problem is*, that displaying the text takes too long time. If i receive
messages in an interval around 25ms, then it is fast enough.
I heard, that it is possible to change any low-level settings of mono to
have a better performance. Does anyone has an idea, how to do or what i have
to do  to solve the problem?
In Windows, the performance is fast enough.

--
View this message in context: http://mono.1490590.n4.nabble.com/Too-slow-performance-on-RichTextBox-tp4485123p4485123.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

(Continue reading)

sharkal | 27 Mar 2012 13:16
Favicon
Gravatar

Re: Too slow performance on RichTextBox?

Hi,
at the meantime i wrote a small test programm where it does the following:

                while (indexCounter < maxIndexCount)
                {
                    var timestamp = (String.Format("{0:yyMMdd
HH:mm:ss:fff}", DateTime.Now));

                    rtxtOutput.AppendText(indexCounter + "  " + timestamp + 
                                                   " This is a output text
to test the output time.\n");
                    indexCounter++;
                    Thread.Sleep(1);
                }
So the while loop do nothing more, than writing the actual  timestamp to the
textbox, sleep 1ms and write the next text out.
If i do this with mono, i have a time differents of ~ 15-20ms , in windows
it is around 1-2ms. 

The Richtextbox is all with the default settings.
Does anyone knows how to get a better performance here?

--
View this message in context: http://mono.1490590.n4.nabble.com/Too-slow-performance-on-RichTextBox-tp4485123p4508543.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

(Continue reading)

Michael Mudge | 27 Mar 2012 14:03

Re: Too slow performance on RichTextBox?

I'm actually surprised at that Windows performance.  Typically Thread.Sleep only has a 15ms resolution...  try appending 15 times between each sleep.

On Mar 27, 2012 7:16 AM, "sharkal" <wolfgang.ginner <at> kapsch.net> wrote:
Hi,
at the meantime i wrote a small test programm where it does the following:

               while (indexCounter < maxIndexCount)
               {
                   var timestamp = (String.Format("{0:yyMMdd
HH:mm:ss:fff}", DateTime.Now));

                   rtxtOutput.AppendText(indexCounter + "  " + timestamp +
                                                  " This is a output text
to test the output time.\n");
                   indexCounter++;
                   Thread.Sleep(1);
               }
So the while loop do nothing more, than writing the actual  timestamp to the
textbox, sleep 1ms and write the next text out.
If i do this with mono, i have a time differents of ~ 15-20ms , in windows
it is around 1-2ms.

The Richtextbox is all with the default settings.
Does anyone knows how to get a better performance here?


--
View this message in context: http://mono.1490590.n4.nabble.com/Too-slow-performance-on-RichTextBox-tp4485123p4508543.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list
Andreia Gaita | 28 Mar 2012 16:52
Picon

Re: Too slow performance on RichTextBox?

On Tue, Mar 27, 2012 at 12:16, sharkal <wolfgang.ginner <at> kapsch.net> wrote:
Hi,
at the meantime i wrote a small test programm where it does the following:

               while (indexCounter < maxIndexCount)
               {
                   var timestamp = (String.Format("{0:yyMMdd
HH:mm:ss:fff}", DateTime.Now));

                   rtxtOutput.AppendText(indexCounter + "  " + timestamp +
                                                  " This is a output text
to test the output time.\n");
                   indexCounter++;
                   Thread.Sleep(1);
               }
So the while loop do nothing more, than writing the actual  timestamp to the
textbox, sleep 1ms and write the next text out.
If i do this with mono, i have a time differents of ~ 15-20ms , in windows
it is around 1-2ms.

The Richtextbox is all with the default settings.
Does anyone knows how to get a better performance here?


You're probably getting the 15ms time on the thread sleep because that is (or was) the time it took to set it up and execute on windows, traditionally. Since timings are sensitive, it wouldn't surprise me if our implementation used slower codepaths or less precise timers to emulate this behaviour (can't say for certain as I haven't looked at the code, but the time is too close to be a coincidence).

Instead of using Thread.Sleep, which is not precise and can vary from to system and from OS version to OS version (as you've noticed), use a wait handle. The WaitOne (ms) overload of the WaitHandle uses precise timers so it should give you much more accuracy and much less overhead, since it doesn't have to mess with the thread. It can be interrupted if you want, and it will return immediately with no blocking if the signal is set (or you pass -1). For your scenario, just create a ManualResetEvent object with false in the constructor (so it's not signaled), and then call WaitOne (1) on it every time you want to wait.



andreia gaita
--------------------
blog.worldofcoding.com
andreiagaita.net
 
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list
sharkal | 29 Mar 2012 08:58
Favicon
Gravatar

Re: Too slow performance on RichTextBox?

Even without any waiting operation ( = without the Thread.Sleep ) it takes 6
seconds for 500 lines => 12ms per line.  In Windows it takes 581ms for the
500 lines...

--
View this message in context: http://mono.1490590.n4.nabble.com/Too-slow-performance-on-RichTextBox-tp4485123p4514630.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list


Gmane