Bug 147109 - Calc SUBSTITUTE function slows down disproportionately as text length increases.
Summary: Calc SUBSTITUTE function slows down disproportionately as text length increases.
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.2.5.2 release
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:7.4.0 target:7.3.1
Keywords: perf
Depends on:
Blocks:
 
Reported: 2022-02-01 14:23 UTC by Vladimir Sokolinskiy
Modified: 2022-03-08 09:53 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Sokolinskiy 2022-02-01 14:23:13 UTC
Run Basic script:

Sub TestSubstitute
  Dim s as String, i as Long, n as Long, t as Long, msg as String
  With ThisComponent.Sheets(0)
    n=20000
    Do While n<=80000
      .getCellByPosition(0,0).setFormula "=REPT("" *""; " & n & ")"
      t=GetSystemTicks()
      .getCellByPosition(0,1).setFormula "=SUBSTITUTE(A1;"" "";""  "")"
      Msgbox "n=" &  n & " time=" & (GetSystemTicks()-t)
      n=n*2
    Loop  
  End With  
End Sub

Result: 
n=20000 time=106
n=40000 time=507
n=80000 time=2230

The running time of the macro increases in proportion to the square of the length of the first argument SUBSTITUTE function. 

Should increase proportionally.
Comment 1 Commit Notification 2022-02-01 14:27:38 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/0b397d8ef0a2615e8e6202804ca2f6cb58436fa5

tdf#147109: Optimize ScInterpreter::ScSubstitute

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 2 Commit Notification 2022-02-10 15:37:27 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/7cddf9609df427c0a87d759cfeab2a6a34ef211b

tdf#147109: Optimize ScInterpreter::ScSubstitute

It will be available in 7.3.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Vladimir Sokolinskiy 2022-02-10 17:11:35 UTC
Mike, thanks a lot!