Skip Recomputes

Merged, abandoned or rejected pull requests are moved here to clear the main Pull Requests forum.
User avatar
shoogen
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Skip Recomputes

Post by shoogen » Wed Jan 28, 2015 3:33 pm

Currently entering a single digit or movig the mouse wheel in a QSpinbox results in a whole doc.recompute() thous locking up FreeCAD unresponsive for many seconds or multiple minutes.
The following patch will allow to set a property

Code: Select all

App.ParamGet('User parameter:BaseApp/Preferences/Document').SetBool('DisableRecomputes',True)
and therefore disable all recomputes until the propery is changed to false (or removed) by either
  • StdCmdRefresh Command(usually form the GUI using Ctrl-R or the "File" toolbar Image)
  • Python (SetBool)
  • The property editor
The following changes since commit dc623f264660b9a671d73d17dee824e002796a0d:

Fixed a typo (2015-01-27 13:57:49 -0200)

are available in the git repository at:

git://github.com/5263/FreeCAD review-skipRecompute

for you to fetch changes up to b4e0bac4e919dc935d7c6e9424e266a8555a3192:

skip recomputes (2015-01-28 16:20:02 +0100)

----------------------------------------------------------------
skip recomputes

src/App/Document.cpp | 131 +++++++++++++++++++++++++++---------------------
src/Gui/CommandDoc.cpp | 7 +++
2 files changed, 80 insertions(+), 58 deletions(-)


or ignoring whitespace (indentation):
src/App/Document.cpp | 15 +++++++++++++++
src/Gui/CommandDoc.cpp | 7 +++++++

User avatar
DeepSOIC
Posts: 6654
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Skip Recomputes

Post by DeepSOIC » Sun Feb 08, 2015 8:50 pm

:P :P :P :P :) :) This is awesome! (though, I haven't tried anything ;) )

wmayer
Site Admin
Posts: 14451
Joined: Thu Feb 19, 2009 10:32 am

Re: Skip Recomputes

Post by wmayer » Mon Feb 09, 2015 11:44 am

It's important to reduce the number of recomputes especially during the work of a longer task and when it stops the user to continue for several seconds or minutes.

But I don't like the way how this is solved for several reasons:
1. The document class shouldn't depend on any user config parameters because this makes it complicated to use it from Python.
2. When e.g. creating a new object you have to explicitly press the Refresh button to create the visual representation which is annoying. Also, if the shape is of a certain size so that the camera position lies inside it then the shape created by the recompute can be really confusing.
3. Once you press the Refresh button the first time the parameter 'DisableRecomputes' is set to false and never set back to the original value. So, any further call of Document::recompute() won't be blocked any more. If this is on purpose then I do not even understand the idea of the solution.


Instead of blocking Document::recompute() I would reduce its number of calls. E.g. the property editor could check the above user config parameter and if set simply doesn't call the recompute() method.

User avatar
shoogen
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Skip Recomputes

Post by shoogen » Mon Feb 09, 2015 1:02 pm

Thanks Werner for reviewing this change.
wmayer wrote:3. Once you press the Refresh button the first time the parameter 'DisableRecomputes' is set to false and never set back to the original value. So, any further call of Document::recompute() won't be blocked any more. If this is on purpose then I do not even understand the idea of the solution.
The reasoning behind this was, to make it as easy as possible for a user who is unaware of this functionality to get back to the normal behavior.
Like I asked somebody to disable the recomputes and save a file with Feature without computing it. So instead of allowing a single manual recompute, running the GUI command restores the normal behavior. I also thought about somehow reseting to be default behavior at startup. But i haven't found a suitable way in the given time.
This mode is intend to make a few changes in row, without being locked out by a blocking GUI.
When I tested this, i sooner or later came to the point when there had to be a recompute. Mostly when Task View commands bumped into null shapes. Since this change is aimed to be included in the 0.15 release as a hidden feature that can be enabled by python commands, I choose that rendering the recompute button useless (easy for me) or allowing single overrides would be a bad option. And providing a proper GUI interface that would permanently (visually) warn the user that recomputes are disables would not be ready until the 0.15 feature freeze. (And i decided not to spend any time on this, until I got confirmation that it will be actually included)
wmayer wrote:Instead of blocking Document::recompute() I would reduce its number of calls. E.g. the property editor could check the above user config parameter and if set simply doesn't call the recompute() method.
To me this is not an either or kind of decision. Reducing the number of recomputes won't suffice. Depending on structure of the document recomputes can be quite be quite expensive. And a lot of times when i tweak an object while parent objects are hidden. I want to keep on working without fully recomputing the whole document.
Recomputes need to run in the background and the GUI needs to be responsive. And then they need to be aborted and restarted if there was a change in the mean time. And of course they needs to be a progress bar if a recomputes takes more than 2 seconds.
But until then I'd like to disable recomputes when they are stopping me to changing several simple properties in a row.
wmayer wrote:1. The document class shouldn't depend on any user config parameters because this makes it complicated to use it from Python.
I consider this as a feature. Completely disabling all recomputes is something that should not be easily used from python (macros or modules). Like someone using the Draft module from a python script, might actually want to prevent doc.recomputes inside there stopping his script and updating the GUI while, the script has not finished. This behavior leaves the GUI with intermediate results. (You probably saw this in earlier versions of the OpenSCAD importer). It might be tempting, to disable recomputes in this scenario as well. But everything that is not meant to work totally parametric might rely on Shapes being correct after. And as there is no way to recalculate a single feature or a subtree up to a certain feature, there is currently no alternative to recomputing the whole document (issue #1957). And those recomputes need be done synchronously.
But my change is only intended for interactive use. A script should, besides offering a simple GUI button, never ever mess with the recompute setting. A script changing user preferences is most probably a bad idea. And a script (globally) disabling the recomputes breaks FreeCAD instantly.

uha4
Posts: 1
Joined: Tue May 05, 2015 12:31 pm

Re: Skip Recomputes

Post by uha4 » Tue May 05, 2015 12:52 pm

Thank you for this patch, it is exactly what i needed.

In my usual workflow FreeCAD and recomputing works just fine, but sometimes i have to edit skeches at the base of komplicated parts. So i need to switch off recomputing while editing the sketch, and than switch it on to normal behavior again.
In an example today recomputing took 20 sec after every little move or constraint.

I first had to find out, how to merge two branches of different git-repros, but now everything works fine. But of course i'm looking forward to find this feature integrated by default.

wmayer
Site Admin
Posts: 14451
Joined: Thu Feb 19, 2009 10:32 am

Re: Skip Recomputes

Post by wmayer » Tue May 05, 2015 4:06 pm

With the offered solution there are a few things I don't like. Soon I'll have a look at this again.

jonnor
Posts: 31
Joined: Mon Feb 23, 2015 12:57 pm

Re: Skip Recomputes

Post by jonnor » Sun Sep 13, 2015 11:05 pm

A typical solution to this problem is to 'debounce' the changes, especially for sliders etc.
That is, wait until some 100ms without any user activity before computing results.

Ideally nothing will freeze the GUI while processing, and processing jobs that take longer can be cancelled. So even if re-computation is in progress (not yet completed) and user changes an input - current recompute (with old values) is canceled - and immediately starts re-computing with new values.

wmayer
Site Admin
Posts: 14451
Joined: Thu Feb 19, 2009 10:32 am

Re: Skip Recomputes

Post by wmayer » Fri Oct 21, 2016 8:26 pm


triplus
Posts: 8452
Joined: Mon Dec 12, 2011 4:45 pm

Re: Skip Recomputes

Post by triplus » Fri Oct 21, 2016 8:35 pm

Nice!

User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Skip Recomputes

Post by NormandC » Sat Apr 15, 2017 3:35 pm

Someone posted a question about this on the G+ FreeCAD community.

As far as I know, there is no documentation anywhere explaining how one is to apply the "skip recomputes" lock.

So, for anyone wondering: right-click on the document label in the Model tree and select "Skip recomputes". When you want the model to be recomputed, right-click on the document label again and select "Mark to recompute". Next you will need to click on the Refresh icon in the standard toolbar or go to the Edit --> Refresh menu.

Post Reply