Sketches 1000 times slower in ubuntu than windows

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Sketches 1000 times slower in ubuntu than windows

Postby quick61 » Fri Sep 27, 2013 9:02 pm

In my post above, (by quick61 » 27 Sep 2013, 12:41), I had originally mentioned that arcs and circles were causing the trouble. Upon further work investigating this problem, I now seem to of narrowed it down to arcs created with the polyline tool. I have edited the above comments to reflect this. Can anyone confirm that this is where the trouble is coming from?

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
bejant
Posts: 6061
Joined: Thu Jul 11, 2013 3:06 pm

Re: Sketches 1000 times slower in ubuntu than windows

Postby bejant » Fri Sep 27, 2013 9:46 pm

triplus wrote: If this is true

A quick video is here
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Sketches 1000 times slower in ubuntu than windows

Postby triplus » Fri Sep 27, 2013 10:08 pm

I wouldn't just limit this to one "sketch". If somebody has both Linux/Windows PC i encourage to test different scenarios in sketcher. If the difference is always huge when on Linux things starts to slow down and on Windows not then i would be interested to know at least why.

I won't switch but would be at least interested to know why the difference and what is the culprit of this behaviour exactly.
wmayer
Site Admin
Posts: 15487
Joined: Thu Feb 19, 2009 10:32 am

Re: Sketches 1000 times slower in ubuntu than windows

Postby wmayer » Sat Sep 28, 2013 9:30 am

I have tested this with a several weeks old FreeCAD installation (on a virtual Ubuntu 12.04) which shows the same symptoms. And with my FreeCAD on a native Ubuntu 12.04 (32-bit) which is now two weeks old has the same problem. Btw, another way of demonstrating this error is to delete Constraint83, close the sketcher, run an undo and refresh the document. This way we can exclude that it has to do with the edit mode.

Nevertheless, I think only a profiler can give us the answer.
nahshon
Posts: 195
Joined: Wed Jul 24, 2013 8:06 pm

Re: Sketches 1000 times slower in ubuntu than windows

Postby nahshon » Sat Sep 28, 2013 10:00 am

I'm using Fedora19. I experienced a big difference (2 or 3 X) in the sketch resolver speed when compiled with Debug and RelWithDebInfo options (I haven't used Release which may give some better optimization).
When a sketch cannot be resolved, the sketcher tries different options which may be really ssssslllllooooww..

Edit: In this case the solver did not fail, therefore there is no fallback to other solvers. See that most on the time is spent in the DogLeg solver.
Adding profile (sprof) output.
Attachments
blegh_profile.zip
(5.82 KiB) Downloaded 29 times
wmayer
Site Admin
Posts: 15487
Joined: Thu Feb 19, 2009 10:32 am

Re: Sketches 1000 times slower in ubuntu than windows

Postby wmayer » Sat Sep 28, 2013 1:30 pm

I'm using Fedora19. I experienced a big difference (2 or 3 X) in the sketch resolver speed when compiled with Debug and RelWithDebInfo options
Of course, my experience is that debug is a factor 10 slower and this is normal behaviour. Anyway, I tried with valgrind and I wasn't able to enter edit mode because it took forever and after an hour I gave up. But from the logged function calls KCacheGrind told me that certain Eigen3 functions are called many million times which I think is by far too much.

Afterwards I ran the debugger to test again and FreeCAD got stuck inside System::solve_DL and to me it seems that the while-loop there is some kind of an endless loop This reminds me to bug https://sourceforge.net/apps/mantisbt/f ... php?id=750
yoshimitsuspeed
Posts: 194
Joined: Fri Oct 19, 2012 4:51 pm

Re: Sketches 1000 times slower in ubuntu than windows

Postby yoshimitsuspeed » Sat Sep 28, 2013 4:09 pm

triplus wrote:I wouldn't just limit this to one "sketch". If somebody has both Linux/Windows PC i encourage to test different scenarios in sketcher. If the difference is always huge when on Linux things starts to slow down and on Windows not then i would be interested to know at least why.

I won't switch but would be at least interested to know why the difference and what is the culprit of this behaviour exactly.
This is definitely not limited to just this sketch. Like I said my manifold flange behaved the same way. It didn't get stuck to the degree this one did after I added that last constraint but it became unbearably slow.
Both that sketch and the one I uploaded work beautifully on my windows machine.
I am also confident I could reproduce the issue as many times as I tried.
quick61 I have experienced the slow down with either the poly line tool or with using individual lines, arcs and circles.

Once I finished my flange in Windows I opened it back up in Ubuntu and although it was much slower than Windows it was much faster than it had been when trying to create it in Ubuntu. Perhaps Windows had warned me about overconstraint that Ubuntu had not or something like that.
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Sketches 1000 times slower in ubuntu than windows

Postby triplus » Sat Sep 28, 2013 5:55 pm

OK let's assume sketcher works way faster on Windows compared to Linux and the difference just gets bigger and bigger in complex sketches. Let's assume it's not a bug because operation does get completed it just take more time or something else happens that aborts "infinite loop" after preset maximum number of iterations is reached.

Reading this:

http://listengine.tuxfamily.org/lists.t ... 00278.html

Could there be difference how Eigen is set up before compile time something like OpenMP is used on Windows and not on Linux? Or could it be OpenMP is the culprit in the first place this sounds very similar to what wmayer is describing:

http://stackoverflow.com/questions/8828 ... p-deadlock

Could simply changing cache or some other setting as suggested make the difference? In this thread we talked a lot about how to improve sketcher performance working with complex sketches:

viewtopic.php?f=8&t=4537

Probably at least on Linux solving this issue would bring great improvements in sketcher performance and that would be really nice especially because there are few more things mentioned that could be tried on top of that. It could just happen this issue could affect end results presented in that thread on how to improve sketcher performance in complex sketches.
wmayer
Site Admin
Posts: 15487
Joined: Thu Feb 19, 2009 10:32 am

Re: Sketches 1000 times slower in ubuntu than windows

Postby wmayer » Mon Sep 30, 2013 8:38 am

OK let's assume sketcher works way faster on Windows compared to Linux and the difference just gets bigger and bigger in complex sketches. Let's assume it's not a bug because operation does get completed it just take more time or something else happens that aborts "infinite loop" after preset maximum number of iterations is reached.
It's definitely a different behaviour in the while-loop. I debugged through and the number of iterations was either 1 or 0. In case of 0 it was because "fx_inf <= tolf" was true and thus it left the loop immediately. So, the different behaviour has probably something to do with Eigen3 directly.
Could there be difference how Eigen is set up before compile time something like OpenMP is used on Windows and not on Linux? Or could it be OpenMP is the culprit in the first place this sounds very similar to what wmayer is describing:
The above excludes that OpenMP can be the culprit because:
1. Eigen3 is a pure template library which means that you don't have a library file. So, if there were some OpenMP related stuff you would set it in the CMakeLists.txt file of the Sketcher module. But there isn't anything.
2. The Windows packages on SF were built with the Express edition of Visual Studio which doesn't offer OpenMP.

Debugging info of System::solve_DL when going to edit mode:
VisualStudio wrote:xsize = 172
csize = 171
err = 1.89e-14
g_inf = 8.6893e-8
fx_inf = 1.13e-7
maxIterNumber = 17200
divergingLim = 1000000000000.0000
alpha = 1.0162805417041498
rel_error = 6.334e-5
err_new = 1.59e-22
dL = 1.89e-14
dF = 1.89e-14
rho = 1.0 (but > 1)
g_inf = 1.39e-11
fx_inf = 1.39e-11
reduce = -1

2nd iteration stops because "fx_inf <= tolf"
wmayer
Site Admin
Posts: 15487
Joined: Thu Feb 19, 2009 10:32 am

Re: Sketches 1000 times slower in ubuntu than windows

Postby wmayer » Mon Sep 30, 2013 10:10 am

This is the output under Ubuntu 12.04 for the first iteration:
xsize=172
csize=171
err=1.89238e-14
g_inf=8.68932e-08
fx_inf=1.13e-07
maxIterNumber=17200
divergingLim=1e+12
alpha=1.01628
rel_error=0.00439761
err_new=3.30248e-10
dL=1.27445e-14
dF=-3.30229e-10
rho=-3.85928e-05
reduce=2
So, as you can see starting from rel_error the values are totally different.