I ended understanding how to use the VStudio profiler well enough to draw some conclusions, and Python is not the culprit (I'll put the FreeCAD version info and details on the procedure at the end. I'll say it here though that the profiling data has been obtained with a Windows build, on a Win10 Home hosted by a Lenovo laptop, AMD Ryzen 5 3500U 2.10 GHz, with 16.0 GB of RAM).
In short, for sketches with (too) many elements and constraints:
- about 58% of the CPU goes into SketchObject::solve(bool), with about 36% into Sketch::solve(void) and 21.5% into Sketch::setupSketch(...) (see Figure 1 below). Most of the CPU goes on eigen's account, but there are some small bits that I'll come back to .
In any case, Python adds on overhead of about 3% to this branch of the call tree. - about 38% of the CPU goes into some async execution with an anonymous (not assigned to any module) lambda - see Figure 2
I have some troubles identifying where this comes from. Initially I thought that it may be some callbacks to pass the results back into Python-land once the "C++ solving" is complete, but I find way more plausible to be thetowards the end of the int System::diagnose(Algorithm alg) method in the GSC.cpp file (because, yeah, eigen again)Code: Select all
auto fut = std::async(&System::identifyDependentParametersSparseQR,this,J,jacobianconstraintmap, pdiagnoselist, /*silent=*/true); makeSparseQRDecomposition( J, jacobianconstraintmap, SqrJT, rank, R, /*transposed=*/true, /*silent=*/false); int paramsNum = SqrJT.rows(); int constrNum = SqrJT.cols(); fut.wait(); // wait for the execution of identifyDependentParametersSparseQR to finish
I will appreciate though an explicit confirmation coming from the ones in-the-know that the first hypothesis (passing back some data into the Python-land by using async callbacks) is rubbish and I can forget about it.
Code: Select all
OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.0.31291 (Git)
Build type: Release
Branch: fallen-fruits
Hash: d763f5a64aef76c94653e7f43e854d3c962210d3
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/Australia (en_AU)
Installed mods:
* CurvedShapes 1.0.4
* freecad.gears 1.0.0
* lattice2 1.0.0
* sheetmetal 0.2.59
- Build the Release configuration following the instructions
- download the file and place it in some directory
- open the solution in VisualStudio and set the FreeCADMainCmd as the solution's 'Startup project'
- edit the FreeCADMainCmd project's properties and, in the Debugging section, set the full path to the solverLoad-2oo.py as the value for the "Command Arguments" property
- in the VisualStudio Debug menu, choose the "Performance Profiler (Alt-F2)"
- select the "CPU Usage" checkbox then press the "Start" button at the bottom of the page
- wait for the execution to finish (in my config, took about 1m40secs) and the report page to finish analyzing the data
- click "Open details" link (under the plot) and set the "current view" to "Module"
- Right click on the list of modules and, on the popup menu, pick "Load all symbols". Wait for the view to settle
- switch the current view to "Call tree"
- explore at you leisure the contributions of various functions to CPU consumption