Bug 145476

Summary: FILEOPEN LibreCalc is running an embedded macro while loading the file
Product: LibreOffice Reporter: adnanbaloch
Component: CalcAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED WORKSFORME    
Severity: normal CC: serval2412
Priority: medium    
Version: 7.3.0.0 alpha0+   
Hardware: All   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Attachments: xlsm file with an embedded macro to calculate countifs calculation time
xlsm file saved as ods
Screenshot showing Calc doing some calculation upon loading countifs.ods

Description adnanbaloch 2021-10-31 16:57:05 UTC
Description:
LibreCalc is running an embedded macro while loading the file which leads to a very long loading time because the macro itself takes around 3 minutes (on Core I7-4770) to finish. This is not what Excel does. Excel loads the xlsm file and then it is our choice to run the macro. Excel does not automatically run an embedded macro upon file open. Once the file is loaded in LibreCalc, I have to run the macro again to get the desired result (total calculation time for countifs on 10,000 rows).

Steps to Reproduce:
1.Open attached xlsm file in LibreCalc
2.Calc will take minutes just to load the file.
3.

Actual Results:
Calc freezes as it is running the embedded macro upon opening xlsm file.

Expected Results:
File should take less than 30 seconds to load. The file I have without macro (https://bugs.documentfoundation.org/attachment.cgi?id=175389) loads quickly. The xlsm file is identical and the only difference is the embedded VBA macro (countifs_benchmark).


Reproducible: Always


User Profile Reset: Yes


OpenGL enabled: Yes

Additional Info:
Version: 7.3.0.0.alpha1+ (x64) / LibreOffice Community
Build ID: c6af59b234e8eb8182dc7f686290524feafd6ed6
CPU threads: 8; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-AE (en_AE); UI: en-US
Calc: CL
Comment 1 adnanbaloch 2021-10-31 17:06:30 UTC
Created attachment 176045 [details]
xlsm file with an embedded macro to calculate countifs calculation time
Comment 2 adnanbaloch 2021-12-02 08:09:24 UTC
xlsm file is now taking almost 7 minutes to load.

Version: 7.3.0.0.beta1+ (x64) / LibreOffice Community
Build ID: 8c137ff0e201c2d0ecd1bb567496dbed8e5eced7
CPU threads: 8; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-AE (en_AE); UI: en-US
Calc: CL
Comment 3 adnanbaloch 2021-12-04 15:29:52 UTC
Created attachment 176694 [details]
xlsm file saved as ods

Saved the xlsm file as ods and now it shows "Adapt row height" progress bar during file load, meaning that some calculation is being done which takes the same amount of time as the embedded macro.
Comment 4 Julien Nabet 2021-12-07 17:22:16 UTC
LO will ask about executing untrusted macro if you do:
- Tools/Options/Security
- choose Medium
If you choose "High" or "Very high", it won't process them.
With "Low", it would process them automatically.


About signed or trusted macros, I'm not sure of what LO does from Medium, does it ask or never ask, what's the difference between signed and trusted macros, etc.

Anyway, opening your xlsm file with Medium, I got the popup which asks to choose between process or not the macro.
Comment 5 adnanbaloch 2021-12-07 18:48:53 UTC
I will try your suggestion in the morning on my office PC. However, the macro does not have any VBA command to make it execute upon File Open and so Excel does not execute it unless I select the macro and run it. Shouldn't Librecalc replicate that behavior?
Comment 6 Julien Nabet 2021-12-07 19:04:21 UTC
(In reply to adnanbaloch from comment #5)
> I will try your suggestion in the morning on my office PC. However, the
> macro does not have any VBA command to make it execute upon File Open and so
> Excel does not execute it unless I select the macro and run it. Shouldn't
> Librecalc replicate that behavior?

Have in mind that it's not because LO asks about disabling or not macros at the opening of the file that it means it'll launch a macro right away.
Anyway, LO takes a lot of time to open it so macro or not, there's a perf pb here.
Comment 7 adnanbaloch 2021-12-08 10:52:42 UTC
Created attachment 176795 [details]
Screenshot showing Calc doing some calculation upon loading countifs.ods

I tried opening countifs.ods with Macro Security set to Medium. It did not ask me to enable macros and froze with "Adapt row height" in the status bar. This definitely seems to be the undesirable execution of the macro because the countifs calculation used by the macro also shows "Adapt row height". Around 7 minutes later, I get the dialog box asking if I want to enable macros.

Version: 7.3.0.0.beta1+ (x64) / LibreOffice Community
Build ID: d7a6869a531d0f2f26c47714466d5d47d78ddbfd
CPU threads: 8; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-AE (en_AE); UI: en-US
Calc: CL
Comment 8 Julien Nabet 2021-12-08 11:04:28 UTC
(In reply to adnanbaloch from comment #7)
> Created attachment 176795 [details]
> Screenshot showing Calc doing some calculation upon loading countifs.ods
> 
> I tried opening countifs.ods with Macro Security set to Medium. It did not
> ask me to enable macros and froze with "Adapt row height" in the status bar.
> This definitely seems to be the undesirable execution of the macro because
> the countifs calculation used by the macro also shows "Adapt row height".
> Around 7 minutes later, I get the dialog box asking if I want to enable
> macros.
Reading your last sentence, it finally asked about macros so LO didn't execute embedded macro.
Of course, as indicated in my previous comment, there's still the perf pb.
If you're not convinced, just add an alert kind message at the beginning of the macro and you'll see if LO shows it or not before it asks to enable or not the macro.
Comment 9 adnanbaloch 2021-12-08 14:09:01 UTC
Thanks for the "alert message" suggestion. That confirmed that it was not a macro execution problem. Issue was that I mistakenly left 10,000 formulas pasted in the sheet when saving it and Calc was recalculating them upon File Open. Please accept my apologies and you may close this bug report.
Comment 10 adnanbaloch 2021-12-08 15:20:27 UTC
An observation. When the xlsm file was saved as ods with LibreCalc, Excel also started recalculating upon file open of ods. Maybe default LibreCalc behavior is to always recalculate upon file open and it saves that behavior in the ods file which then forces Excel to also do the same?
Comment 11 Julien Nabet 2021-12-08 17:32:01 UTC
(In reply to adnanbaloch from comment #10)
> An observation. When the xlsm file was saved as ods with LibreCalc, Excel
> also started recalculating upon file open of ods. Maybe default LibreCalc
> behavior is to always recalculate upon file open and it saves that behavior
> in the ods file which then forces Excel to also do the same?

I'm not expert about recalculation but I found this link which may interest you:
https://help.libreoffice.org/latest/en-US/text/scalc/01/06080000.html

For the rest, following to your previous comment, let's put this one to WFM.