Recent Sketcher Performance Degradation

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!
Syres
Veteran
Posts: 2902
Joined: Thu Aug 09, 2018 11:14 am

Recent Sketcher Performance Degradation

Post by Syres »

I re-compiled FreeCAD this morning before I had a new (simple) model to create. As I constructed the one and only sketch I was presented with a stuttering response from Sketcher/Solver. Therefore I decided to give some accurate evidence based feedback. Using the below macro (after opening a new document and starting a new Sketch in X-Y Plane), which I've quoted in the past is only used for benchmarking but can be for real work epicycloidal gear.

Using FreeCAD Daily from the macro completed in 15.489059448242188 seconds but using today's compiled build it completes in 555.14466547966 seconds. That's not exactly a subtle worsening in performance but I hope this constructive feedback will be of use.

Old FreeCAD Daily Build:

OS: Linux Mint 19.3 (X-Cinnamon/cinnamon)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: 08854bcc717b89fe437b671edc2098c603ff5dec
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)



This morning's compiled build:

OS: Linux Mint 19.3 (X-Cinnamon/cinnamon)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23491 (Git)
Build type: Unknown
Branch: master
Hash: 04337034ce0aeff5434d3930cad0db2fb3d2aa36
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)


Code: Select all

import time
start_time = time.time()
LargeRadius = 560.0
SmallRadius = 20.0
nbPas = 480
excentrique = 12.0
EpiCycloidAngle = 0.0
# Large line length= sum of the radiuses
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(10,23,0),App.Vector(27.354679,55.016010,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1)) 
c=ActiveSketch.addConstraint(Sketcher.Constraint('Distance',0,LargeRadius+SmallRadius))
ActiveSketch.setVirtualSpace(c, True) 
La=ActiveSketch.addConstraint(Sketcher.Constraint('Angle',-1,1,0,1,2*3.141592653589793*EpiCycloidAngle/360.0))
ActiveSketch.setVirtualSpace(La, True) 
#ActiveSketch.setDatum(La,App.Units.Quantity('0.000000 deg'))

# arc de cercle small radius
ActiveSketch.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(25,31,0),App.Vector(0,0,1),12),-2,0.4),False)
c=ActiveSketch.addConstraint(Sketcher.Constraint('PointOnObject',1,1,0))  # start of the Arc on the large line
ActiveSketch.setVirtualSpace(c, True) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident',1,3,0,2)) #center at end of the large line
c=ActiveSketch.addConstraint(Sketcher.Constraint('Radius',1,SmallRadius))
ActiveSketch.setVirtualSpace(c, True) 
 
#  Small line
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(26,35,0),App.Vector(34,38,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident',0,2,2,1)) #start at the end of the large line
c=ActiveSketch.addConstraint(Sketcher.Constraint('Distance',2,excentrique))
ActiveSketch.setVirtualSpace(c, True)
c=App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('PointOnObject',1,2,2))
ActiveSketch.setVirtualSpace(c, True)
Sa=ActiveSketch.addConstraint(Sketcher.Constraint('Angle',0,2,2,1,0)) #creer contrainte a 0 (radian))
ActiveSketch.setVirtualSpace(Sa, True)          # make the angle constraint invisible to improve drawing understanding  

n=0
Sv= ActiveSketch.Geometry[2].EndPoint
Lad = (360.000000/nbPas)
Sad = Lad * (LargeRadius/SmallRadius)
if True:
  while n < nbPas :
    n += 1
    App.ActiveDocument.Sketch.setDatum(La,App.Units.Quantity(str(Lad*n+EpiCycloidAngle) + ' deg'))
    App.ActiveDocument.Sketch.setDatum(Sa,App.Units.Quantity(str(Sad*n) + ' deg'))
    Ev= App.ActiveDocument.Sketch.Geometry[2].EndPoint
    App.ActiveDocument.Sketch.addGeometry(Part.LineSegment(Sv,Ev),False)
    Sv=Ev
    
    #clean up of the geometries used to buid the epicycloid
  App.ActiveDocument.Sketch.delGeometry(2)
  App.ActiveDocument.Sketch.delGeometry(1)
  App.ActiveDocument.Sketch.delGeometry(0)

print("--- %s seconds ---" % (time.time() - start_time))
drmacro
Veteran
Posts: 9002
Joined: Sun Mar 02, 2014 4:35 pm

Re: Recent Sketcher Performance Degradation

Post by drmacro »

Just for another data point.

If I run the macro with the sketch closed it completes in 11 seconds.

If I run it with the sketch open it completes in 22 seconds.

In both cases repeatable within +-0.2seconds.

Todays daily.

OS: Ubuntu 20.04.1 LTS (XFCE/ubuntustudio)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: 04337034ce0aeff5434d3930cad0db2fb3d2aa36
Python version: 3.8.5
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.3.0
Locale: English/United States (en_US)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Syres
Veteran
Posts: 2902
Joined: Thu Aug 09, 2018 11:14 am

Re: Recent Sketcher Performance Degradation

Post by Syres »

Just to account for my paranoia, I tried renaming my config files and then I completely deleted my source and build folders before starting compile routine from scratch. The result of this was no improvement still very slooooooow with build rev 23495 and still (relatively) speedy using my old Daily build.
abdullah wrote: I'd be interested to know if you noticed any performance hit in your testing
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Recent Sketcher Performance Degradation

Post by abdullah »

Syres wrote: Wed Dec 23, 2020 3:55 pm Just to account for my paranoia, I tried renaming my config files and then I completely deleted my source and build folders before starting compile routine from scratch. The result of this was no improvement still very slooooooow with build rev 23495 and still (relatively) speedy using my old Daily build.
abdullah wrote: I'd be interested to know if you noticed any performance hit in your testing
This is very worrying.

If you tell me you have a difference of 2x, even 4x if you are using the block constraint. Then I could understand that some multi-threading is not working. But, not the difference you indicate. And you are using a Linux build as I am. I will investigate.

In the meantime, could you check that your QR decomposition algorithm is SparseQR? Do you have a way to check if two cores are working during part of the solving at least?
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Recent Sketcher Performance Degradation

Post by abdullah »

drmacro wrote: Tue Dec 22, 2020 7:26 pm Just for another data point.

If I run the macro with the sketch closed it completes in 11 seconds.

If I run it with the sketch open it completes in 22 seconds.

In both cases repeatable within +-0.2seconds.

Todays daily.

OS: Ubuntu 20.04.1 LTS (XFCE/ubuntustudio)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: 04337034ce0aeff5434d3930cad0db2fb3d2aa36
Python version: 3.8.5
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.3.0
Locale: English/United States (en_US)
Is there any way that you could do this test in an older version of 0.19 (before the sketch changes)? What I would be interested in knowing is if in the old master there was also a x2 factor between sketch open and closed, or this was introduced by the recent changes.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Recent Sketcher Performance Degradation

Post by wmayer »

Syres wrote: Tue Dec 22, 2020 4:59 pm Using FreeCAD Daily from the macro completed in 15.489059448242188 seconds but using today's compiled build it completes in 555.14466547966 seconds. That's not exactly a subtle worsening in performance but I hope this constructive feedback will be of use.
Syres wrote: Tue Dec 22, 2020 4:59 pm Old FreeCAD Daily Build:

Version: 0.19.
Build type: Release
Branch: unknown
Syres wrote: Tue Dec 22, 2020 4:59 pm This morning's compiled build:

Version: 0.19.23491 (Git)
Build type: Unknown
Branch: master
Be careful with such comparisons! Your old daily FreeCAD build obviously is from the PPA that creates a Release build and thus has enabled some optimization while your local build isn't a Release build without any optimization.

Here is the build log of a package: https://launchpadlibrarian.net/51284299 ... ING.txt.gz
The relevant CMake options are:
cmake -DCMAKE_BUILD_TYPE=None "-DCMAKE_C_FLAGS=-g -O2 "-DCMAKE_CXX_FLAGS=-g -O2 ...
where -02 is used. So, to compare both FreeCAD versions you must rebuild you local versions with the above CMake options.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Recent Sketcher Performance Degradation

Post by wmayer »

I created a Release build where CMAKE_BUILD_TYPE is set to Release and your script took 15.9 seconds.

So, performance is still OK and there is no regression.

OS: Ubuntu 18.04.5 LTS (XFCE/xubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23520 (Git)
Build type: Release
Branch: master
Hash: d89cd953a2e785b628c89ad75e2f2182f8413736
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)

Btw, in order to make the script working I had to made some adjustments:

Code: Select all

import FreeCAD
import Sketcher
import time

start_time = time.time()
LargeRadius = 560.0
SmallRadius = 20.0
nbPas = 480
excentrique = 12.0
EpiCycloidAngle = 0.0

doc = FreeCAD.newDocument()
ActiveSketch = doc.addObject("Sketcher::SketchObject")
# Large line length= sum of the radiuses
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(10,23,0),App.Vector(27.354679,55.016010,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1)) 
c=ActiveSketch.addConstraint(Sketcher.Constraint('Distance',0,LargeRadius+SmallRadius))
ActiveSketch.setVirtualSpace(c, True) 
La=ActiveSketch.addConstraint(Sketcher.Constraint('Angle',-1,1,0,1,2*3.141592653589793*EpiCycloidAngle/360.0))
ActiveSketch.setVirtualSpace(La, True) 
#ActiveSketch.setDatum(La,App.Units.Quantity('0.000000 deg'))

# arc de cercle small radius
ActiveSketch.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(25,31,0),App.Vector(0,0,1),12),-2,0.4),False)
c=ActiveSketch.addConstraint(Sketcher.Constraint('PointOnObject',1,1,0))  # start of the Arc on the large line
ActiveSketch.setVirtualSpace(c, True) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident',1,3,0,2)) #center at end of the large line
c=ActiveSketch.addConstraint(Sketcher.Constraint('Radius',1,SmallRadius))
ActiveSketch.setVirtualSpace(c, True) 
 
#  Small line
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(26,35,0),App.Vector(34,38,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident',0,2,2,1)) #start at the end of the large line
c=ActiveSketch.addConstraint(Sketcher.Constraint('Distance',2,excentrique))
ActiveSketch.setVirtualSpace(c, True)
c=ActiveSketch.addConstraint(Sketcher.Constraint('PointOnObject',1,2,2))
ActiveSketch.setVirtualSpace(c, True)
Sa=ActiveSketch.addConstraint(Sketcher.Constraint('Angle',0,2,2,1,0)) #creer contrainte a 0 (radian))
ActiveSketch.setVirtualSpace(Sa, True)          # make the angle constraint invisible to improve drawing understanding  

n=0
Sv= ActiveSketch.Geometry[2].EndPoint
Lad = (360.000000/nbPas)
Sad = Lad * (LargeRadius/SmallRadius)
if True:
  while n < nbPas :
    n += 1
    ActiveSketch.setDatum(La,App.Units.Quantity(str(Lad*n+EpiCycloidAngle) + ' deg'))
    ActiveSketch.setDatum(Sa,App.Units.Quantity(str(Sad*n) + ' deg'))
    Ev= ActiveSketch.Geometry[2].EndPoint
    ActiveSketch.addGeometry(Part.LineSegment(Sv,Ev),False)
    Sv=Ev
    
    #clean up of the geometries used to buid the epicycloid
  ActiveSketch.delGeometry(2)
  ActiveSketch.delGeometry(1)
  ActiveSketch.delGeometry(0)

print("--- %s seconds ---" % (time.time() - start_time))
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Recent Sketcher Performance Degradation

Post by abdullah »

wmayer wrote: Wed Dec 23, 2020 10:47 pm Be careful with such comparisons! Your old daily FreeCAD build obviously is from the PPA that creates a Release build and thus has enabled some optimization while your local build isn't a Release build without any optimization.
Thanks for checking this. I did not realise that one was a debug build, I misread to different versions from the PPA. :)
Syres
Veteran
Posts: 2902
Joined: Thu Aug 09, 2018 11:14 am

Re: Recent Sketcher Performance Degradation

Post by Syres »

abdullah wrote: Thu Dec 24, 2020 8:54 am
wmayer wrote: Wed Dec 23, 2020 10:47 pm Be careful with such comparisons! Your old daily FreeCAD build obviously is from the PPA that creates a Release build and thus has enabled some optimization while your local build isn't a Release build without any optimization.
I did not realise that one was a debug build
@wmayer, every day is a learning day, I've used the Wiki Compile on Linux Out-Of-Source Build for over 12 months and never thought until the other day that there was any performance issues so I apologise for my ignorance. I've built significant real world models using that build, only a month ago a model with 24 Tech drawings in one project file for the mullions round a bay window and it all ran fine hence my reason for raising the post.

@abdullah, the last thing I intended was to waste any of your valuable time, I will only compare apples with apples in future. Normally I'm using the script to ensure (usually a Windows) new user has decent enough hardware to achieve around 15 seconds for the benchmark. In the past I was handed an old Toshiba laptop which came back at nearly a minute and therefore rejected it on that basis using the Windows LP build and I'd still do that today.

I'll re-read the Wiki and if I think a note highlighting the awareness of this is needed then I'll raise it in the appropriate place, as you maybe able to tell I'm a little shocked by this.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Recent Sketcher Performance Degradation

Post by abdullah »

Syres wrote: Thu Dec 24, 2020 9:51 am @abdullah, the last thing I intended was to waste any of your valuable time, I will only compare apples with apples in future. Normally I'm using the script to ensure (usually a Windows) new user has decent enough hardware to achieve around 15 seconds for the benchmark. In the past I was handed an old Toshiba laptop which came back at nearly a minute and therefore rejected it on that basis using the Windows LP build and I'd still do that today.
No problem. In fact, I saw Werner post when I was going to get serious about this. So basically I skipped over ;)

It is always good to have users who care about testing the performance. It is important. :D
Post Reply