After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 326595 - Gnumeric calculates both branches of "if"
Gnumeric calculates both branches of "if"
Status: RESOLVED FIXED
Product: Gnumeric
Classification: Applications
Component: General
git master
Other All
: Normal normal
: ---
Assigned To: Jody Goldberg
Jody Goldberg
Depends on:
Blocks: 567389
 
 
Reported: 2006-01-11 13:26 UTC by Manuel Clos
Modified: 2009-01-20 16:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Example ilustrating the bug (27.75 KB, application/x-bzip)
2006-01-11 13:28 UTC, Manuel Clos
  Details
Preliminary patch (2.89 KB, patch)
2009-01-16 18:20 UTC, Morten Welinder
needs-work Details | Review
Even simpler patch (1.71 KB, patch)
2009-01-16 19:56 UTC, Morten Welinder
none Details | Review

Description Manuel Clos 2006-01-11 13:26:55 UTC
Hi,

It seems that gnumeric is doing extra work:

if (C5 = "yes"; very_complicated_calculation; "")

when I change C5 value from "yes" to "no" or from "no" to "foo", gnumeric uses almost half the cpu that will use for the very_complicated_calculation.

Demo file attached.

Note 1: Exporting the file to .xls and loading it with OpenOffice.org 2, when using a "no" value, no cpu is used.

Note 2: Calculation under OpenOffice.org is faster.
Comment 1 Manuel Clos 2006-01-11 13:28:07 UTC
Created attachment 57152 [details]
Example ilustrating the bug
Comment 2 Morten Welinder 2006-01-11 22:11:41 UTC
This is true: "if" evaluates both the "true" and the "false" branch.  This
has to do with getting the semantics of implicit iteration right.

If this was a visible problem for a real (== non-test) spreadsheet we would
be more concerned than we currently are.

There is, incidentally, another reason why Gnumeric takes longer on this
sheet: Our "product" function takes a good deal of care avoiding overflow
and underflow in intermedia results.  That takes time, but yields better
results in general.
Comment 3 Manuel Clos 2006-01-11 22:39:00 UTC
I was trying to solve my perfomance problem, because I use sumproduct a lot (2 or 3 seconds freeze every time I modify a cell that causes recalculations). This is, don't do the sumproduct until I need some statistics. I tried using the "if" solution and found that it also uses lots of cpu.

The example is just to make it evident. I haven't tried any older gnumeric versions though.
Comment 4 Morten Welinder 2006-01-11 23:45:54 UTC
Setting os=all, and version=cvs.  There is nothing Linux-specific here
and the version it will be fixed for is cvs HEAD.  We will not do it
for the stable series.

It sounds like your immediate problem could be solved by setting manual
recalculation.
Comment 5 Manuel Clos 2006-01-12 09:11:09 UTC
Sorry, refreshing the page kept version=cvs and os=linux.

I need automatic recalculation in the sheet.

Thanks!
Comment 6 Morten Welinder 2009-01-15 20:55:49 UTC
Bringing this back onto the radar.

To solve this problem, we need to be able to tell (statically) if a given
call to "if" might require implicit iteration.

That, in turn, means that we need to tell if a given sub-expression can
return an array or a cell range.  That means we need that ability per
function.  I think a flag with possible values "maybe" or "no" should
be enough.

Calls to g_warning/g_error can be added to check the flag against
run-time results.  Our test suite ought to test a good part of this.

If we have that information and look at a given call to IF where none
of the up to three arguments can return array/range, then that call
can be changed to a non-strict version of IF.
Comment 7 Morten Welinder 2009-01-16 18:20:51 UTC
Created attachment 126598 [details] [review]
Preliminary patch

Brutally simple way of fixing this.  Needs a bit of work, though: the "if2"
function should not be visible from the outside.
Comment 8 Morten Welinder 2009-01-16 19:56:54 UTC
Created attachment 126603 [details] [review]
Even simpler patch
Comment 9 Morten Welinder 2009-01-20 16:20:32 UTC
A variant of the last patch has been committed.

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.