Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » LineEdit, EditFields, DocEdit » How to do fast Append & scroll in LineEdit with MT?
How to do fast Append & scroll in LineEdit with MT? [message #45646] Fri, 18 December 2015 14:58 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Hi!

I have this program that runs other tasks using LocalProcess. The execution can take sometime a lot of time, and can even hang, so I decided to try MT. I used the callback posting mechanism to post a callback to the application with a new output fragment. And I'm using a LineEdit to show the output as it is created.

I saw no obvious way of inserting something to the end of the text in the LineEdit, so I used edit.Set(edit.Get() + t). This was really slow and unresponsive. Now I'm trying to use Insert and some sort of a position returned by LineEdit. But the position system that this control uses isn't the most intuitive and I always had to use a lot of trial and error to get it right. Using Append now is much more responsive (still not enough, I probably need to update it only every 1K of output or something), but the output is mangled, which makes me believe that I am using a wrong position as a parameter to Insert.

So my question is: how to easily and efficiently append something to LineEdit in a MT environment. And should I use GUI lock instead of post-backs?
Re: How to do fast Append & scroll in LineEdit with MT? [message #45647 is a reply to message #45646] Fri, 18 December 2015 15:34 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
I did some further testing. I am using a task that outputs all numbers form 0 to 99999 as a test. Running it the Windows console is very slow, over 4 seconds. But running it though LocalProcess is about 230 ms. So my goal is to get relatively close to 230 ms (300-400 ms will do) while still having the program be responsive.

I tested:
1. Updating the whole LineEdit. Unusably slow of course.
2. Using Insert and then ScrollEnd. Ignoring the corrupted output, I got almost 3 seconds.
3. Using only Insert. 2.4 seconds.
4. Using my favorite control: ColumnList! Plus using SetCursor to move to last element. I need to pre-process the output since ColumnList does not understand '\n', but it only takes 280 ms.
5. ColumnList and no SetCursor: somehow on average 10 ms slower Smile.

So the conclusion is that maybe LineEdit is not the right control to use here?

Re: How to do fast Append & scroll in LineEdit with MT? [message #45649 is a reply to message #45647] Fri, 18 December 2015 19:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
All this sound very similar to theide Console... ide/Console.cpp Smile

And yes, best it to append by insert at the end. Use GuiLock.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45675 is a reply to message #45649] Mon, 21 December 2015 12:39 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Yeah, using the code from Console that manipulates selection and uses Paste I got 11 seconds.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45679 is a reply to message #45675] Mon, 21 December 2015 19:15 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi cbporter,

I may be wrong, but It looks like you are trying to display every single update while you also want quick display.
Maybe you should disconnect display frequency from update frequency by appending all text adds in between two displays in one big text update (if this is possible with you're needs of corse)

I did something close to this when managing undo stack in my GraphCtrl : when doing quick zooming or panning (less than 300ms in between two actions), I append all actions in order to make one final undo action.

Hope this helps
Re: How to do fast Append & scroll in LineEdit with MT? [message #45692 is a reply to message #45679] Tue, 22 December 2015 14:03 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Didier wrote on Mon, 21 December 2015 20:15
Hi cbporter,

I may be wrong, but It looks like you are trying to display every single update while you also want quick display.
Maybe you should disconnect display frequency from update frequency by appending all text adds in between two displays in one big text update (if this is possible with you're needs of corse)

I did something close to this when managing undo stack in my GraphCtrl : when doing quick zooming or panning (less than 300ms in between two actions), I append all actions in order to make one final undo action.

Hope this helps

Hi Didier,

Sure, the final solution will probably cache the updates and only call it every N ms, but it still does not hurt to investigate the overall performance. Here is some valuable findings: they way TheIDE does it is 4+ times slower than my old solution.

And quite honestly, the performance of LineEdit is downright random. As an example, this is the shortest solution I found:

edtPane.Insert(edtPane.Total(), str); // I added a test getter for total


This executes in 1.4 seconds.

But this:
edtPane.Insert(edtPane.Total(), str);
edtPane.ScrollEnd();


Executes in 300 ms. Without any caching. And has the advantage of scrolling the LineEdit to the end. This solution is 36 times faster than the one inspired from TheIDE/Console.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45698 is a reply to message #45692] Wed, 23 December 2015 19:47 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Well, it looks like adding
edtPane.ScrollEnd()
after insert prevents from drawing all text (added and present) : it probably only draws the last visible lines.

Just a guess:
* You're solution : render time is almost constant ( mostly not linked to text size).
* Original solution (without "ScrollEnd()") : display time directly linked to total text length

Re: How to do fast Append & scroll in LineEdit with MT? [message #45699 is a reply to message #45675] Thu, 24 December 2015 00:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
cbpporter wrote on Mon, 21 December 2015 12:39
Yeah, using the code from Console that manipulates selection and uses Paste I got 11 seconds.


If you provide me with testcase, I can either advise what you are doing wrong, or, if nothing, optimize LineEdit Smile

IMO there is not technical reason why that should be slow.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45700 is a reply to message #45699] Thu, 24 December 2015 03:11 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
mirek wrote on Wed, 23 December 2015 18:03
cbpporter wrote on Mon, 21 December 2015 12:39
Yeah, using the code from Console that manipulates selection and uses Paste I got 11 seconds.


If you provide me with testcase, I can either advise what you are doing wrong, or, if nothing, optimize LineEdit Smile

IMO there is not technical reason why that should be slow.


A test case is very simple. Try to compile in TheIDE code, which has a lot of errors/warnings, and TheIDE will frieze for several seconds. I do not know which part of TheIDE is responsible for that (parser, console, or new grid control with error messages), but profiling can help to figure that out. I spotted the problem when tried to compile one of my projects with a wrong compiler.


Regards,
Novo
Re: How to do fast Append & scroll in LineEdit with MT? [message #45701 is a reply to message #45700] Thu, 24 December 2015 05:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Novo wrote on Thu, 24 December 2015 03:11
mirek wrote on Wed, 23 December 2015 18:03
cbpporter wrote on Mon, 21 December 2015 12:39
Yeah, using the code from Console that manipulates selection and uses Paste I got 11 seconds.


If you provide me with testcase, I can either advise what you are doing wrong, or, if nothing, optimize LineEdit Smile

IMO there is not technical reason why that should be slow.


A test case is very simple. Try to compile in TheIDE code, which has a lot of errors/warnings, and TheIDE will frieze for several seconds. I do not know which part of TheIDE is responsible for that (parser, console, or new grid control with error messages), but profiling can help to figure that out. I spotted the problem when tried to compile one of my projects with a wrong compiler.


I was fixing that about year ago. Is it still an issue with current release? (Just want to be sure before I dive into it again...)

Anyway, the issue back then was not with LineEdit, but problem with pipe.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45702 is a reply to message #45701] Thu, 24 December 2015 06:16 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
mirek wrote on Wed, 23 December 2015 23:49
I was fixing that about year ago. Is it still an issue with current release? (Just want to be sure before I dive into it again...)

Anyway, the issue back then was not with LineEdit, but problem with pipe.

This happened to me a couple of weeks ago. I ran a Windows version of TheIDE. Unfortunately, I cannot profile anything by myself because my Linux machine is broken. Well, I can try to run Linux in a VM ...

BTW, could you please fix e-mail notifications for me? I'm not having them since you upgraded forum's software. This is very inconvenient and I'm missing post I could've answered.

Thanks.


Regards,
Novo
Re: How to do fast Append & scroll in LineEdit with MT? [message #45703 is a reply to message #45699] Thu, 24 December 2015 10:25 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
mirek wrote on Thu, 24 December 2015 01:03
cbpporter wrote on Mon, 21 December 2015 12:39
Yeah, using the code from Console that manipulates selection and uses Paste I got 11 seconds.


If you provide me with testcase, I can either advise what you are doing wrong, or, if nothing, optimize LineEdit Smile

IMO there is not technical reason why that should be slow.

Sorry, I won't be able to provide test-cases probably until January. But if you are curious, you could run a program that print numbers form 0 to 100000 in a for loop, each followed by a '\n', an time how much it takes for TheIDE to capture and display the output.

There will be differences based on relative computer power, but for me with my solution it takes 300 ms, so that's a starting point. If it is hundreds of ms, it is fine. If it is 11 seconds, like in my case, there might be some problems Smile.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45705 is a reply to message #45646] Sat, 26 December 2015 12:55 Go to previous messageGo to next message
deep is currently offline  deep
Messages: 263
Registered: July 2011
Location: Bangalore
Experienced Member
Generally in this scenario I use Append to string then Paste it to LineEdit. ( Paste append the text to LineEdit );

	LineEdit le1;
	
	String s;
	
	loop { s << "Your values and text\n" ;}
	le1.Paste(s.ToWString()),


Even if we append the LineEdit with 100000 line in 100 sec.
This scroll speed also is fast to read and comprehend the values as it scrolls.

When value generation is very fast then I use 2 strings. And pasting to Line edit from another thread.

String s0,s1;

Start with putting values to s0
When s0 is full start filling s1. Paste s0 to LineEdit.
When s1 is full swith filling the s0. Paste s1 to LineEdit.


It is possible to switch strings on time basis or on Number of lines in a string basis. Probably both together.

depends on requirement.

This works for me. I work with real fast data capture.


Warm Regards

Deepak

[Updated on: Sat, 26 December 2015 13:35]

Report message to a moderator

Re: How to do fast Append & scroll in LineEdit with MT? [message #45809 is a reply to message #45701] Sat, 09 January 2016 04:50 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
I posted profiling info here.

Thanks.


Regards,
Novo
Re: How to do fast Append & scroll in LineEdit with MT? [message #45843 is a reply to message #45809] Tue, 12 January 2016 12:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Novo wrote on Sat, 09 January 2016 04:50
I posted profiling info here.

Thanks.


I have checked it and if I understand it right, the issue has nothing to do with LineEdit. The problem there seems to be related to capturing errors for that nice new (since the last year) error window and with some checks invoked by ProcessEvents. I believe both could be fixed quite easily.

Mirek
Re: How to do fast Append & scroll in LineEdit with MT? [message #45854 is a reply to message #45843] Wed, 13 January 2016 15:31 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
I don't really know what that profiling info is about, but for what I need it to do (capture medium size outputs in LineEdit from a different thread), the method I detailed above:

edtPane.Insert(edtPane.GetTotal(), str);
edtPane.ScrollEnd();


Is the only one that has great performance, so I consider this issue closed for me. I get a 10-20% penalty for capturing data to LineEdit vs. not capturing, so that is perfectly acceptable.

Copy and pasting the code from TheIDE behaved horribly though, maybe I did something wrong.

And there seems to be nothing wrong with LineEdit, as long as you use it right.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45857 is a reply to message #45843] Thu, 14 January 2016 04:56 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
mirek wrote on Tue, 12 January 2016 06:59
Novo wrote on Sat, 09 January 2016 04:50
I posted profiling info here.

Thanks.


I have checked it and if I understand it right, the issue has nothing to do with LineEdit. The problem there seems to be related to capturing errors for that nice new (since the last year) error window and with some checks invoked by ProcessEvents. I believe both could be fixed quite easily.

Mirek


Yes. It looks like the problem is not related to LineEdit directly. As I wrote previously " I do not know which part of TheIDE is responsible for that (parser, console, or new grid control with error messages)"
I cannot see anything related to the error window. It is all about Console which spends almost all time in Ide::FindLineError.


Regards,
Novo
Re: How to do fast Append & scroll in LineEdit with MT? [message #45860 is a reply to message #45857] Thu, 14 January 2016 07:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Novo wrote on Thu, 14 January 2016 04:56
mirek wrote on Tue, 12 January 2016 06:59
Novo wrote on Sat, 09 January 2016 04:50
I posted profiling info here.

Thanks.


I have checked it and if I understand it right, the issue has nothing to do with LineEdit. The problem there seems to be related to capturing errors for that nice new (since the last year) error window and with some checks invoked by ProcessEvents. I believe both could be fixed quite easily.

Mirek


Yes. It looks like the problem is not related to LineEdit directly. As I wrote previously " I do not know which part of TheIDE is responsible for that (parser, console, or new grid control with error messages)"
I cannot see anything related to the error window. It is all about Console which spends almost all time in Ide::FindLineError.


That FindLineError is called to determine whether line just added to console is line with error and should be put to error table (not technically a window). ide/Errors.cpp.
Re: How to do fast Append & scroll in LineEdit with MT? [message #45875 is a reply to message #45860] Mon, 18 January 2016 10:00 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Optimized...
Previous Topic: What do you think about this approach to making CodeEditor more user extendable?
Next Topic: NotNull can be fooled
Goto Forum:
  


Current Time: Thu Mar 28 12:52:43 CET 2024

Total time taken to generate the page: 0.01165 seconds