Bug 132388 - BASIC: Replace is awfully slow
Summary: BASIC: Replace is awfully slow
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.1 all versions
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:7.0.0 target:7.4.0 target:7.3....
Keywords: perf
Depends on:
Blocks:
 
Reported: 2020-04-24 21:48 UTC by Mike Kaganski
Modified: 2022-02-07 16:07 UTC (History)
4 users (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 Mike Kaganski 2020-04-24 21:48:13 UTC
> Sub TestReplace
>   n=100000
>   s=Space(n) 
>   t=GetSystemTicks
>   s=Replace(s, " ", "*",1,-1,1) 
>   Msgbox "time=" & (GetSystemTicks-t)
> End Sub

This code runs about 7 s on my system, and time increases as O(n^2). It must run instantly.
Comment 1 Mike Kaganski 2020-04-24 21:53:59 UTC
https://gerrit.libreoffice.org/c/core/+/92884
Comment 2 Commit Notification 2020-04-25 06:01:32 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/dd06a8a2caf93707fbf29c7264cf41f8ec9d4c6d

tdf#132388: reimplement SbRtl_Replace

It will be available in 7.0.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 3 Xisco Faulí 2020-04-28 10:32:09 UTC
time=26 in

Version: 7.0.0.0.alpha0+
Build ID: 4ba1909f12b49f020195b5e767045340717ce6df
CPU threads: 4; OS: Linux 4.19; UI render: default; VCL: x11; 
Locale: en-US (en_US.UTF-8); UI-Language: en-US
Calc: threaded

@Mike Kaganski, thanks for fixing this issue!
Comment 4 Xisco Faulí 2020-04-28 10:44:45 UTC
time=86010 in

Version 4.1.0.0.alpha0+ (Build ID: efca6f15609322f62a35619619a6d5fe5c9bd5a)
Comment 5 Andreas Heinisch 2022-01-29 14:16:09 UTC
Should we reopen this one because of Bug 142487? Is there a possibility to add performance checks to LO to prevent regressions like the "normal" macro tests?
Comment 6 Mike Kaganski 2022-01-30 07:01:12 UTC
(In reply to Andreas Heinisch from comment #5)
> Should we reopen this one because of Bug 142487? Is there a possibility to
> add performance checks to LO to prevent regressions like the "normal" macro
> tests?

I suppose a separate report is better, with the two bugs are See Also.

The problem is the repeated calls to TextSearch::searchForward, which takes the search string, and internally calls the transliteration for each call. That does multiple allocations, putting the performance to the knees.

I suggest to introduce a XTextSearch3 interface that would allow to set the searched string (in addition to search substring) once, and then call search repeatedly, without passing the string. Or maybe instead of adding the interface, cache the processed string in the class, and re-use it when the passed searched string is the same. But that is all for another issue :-)
Comment 7 Mike Kaganski 2022-01-30 07:37:14 UTC
(In reply to Mike Kaganski from comment #6)

Or better put the caching into TransliterationImpl, which would reset the cache on changing its properties (e.g., loading modules), and thus the optimization would be available for all transliteration users automatically.
Comment 8 Commit Notification 2022-01-30 14:20:19 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a03b7d2a8d0f0fd7e710202bbeecf165f0fcd06a

tdf#132388: reimplement fix for tdf#142487

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 9 Commit Notification 2022-01-31 10:24:43 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/81a3d9b4bf471158de00d2fbb63fca420da94a38

tdf#132388: add unit test

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 10 Commit Notification 2022-02-01 12:56:31 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/8efa3dd53aaf98ed258c9f340800504c9e874b78

tdf#132388: reimplement fix for tdf#142487

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 11 Commit Notification 2022-02-01 16:37:33 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/79c7f4378ec38c0e153032cccb437a665b318045

tdf#132388: add unit test

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 12 Commit Notification 2022-02-07 16:07:28 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-2":

https://git.libreoffice.org/core/commit/3fa7c7618500bf5914e19cb3714f301f7bff305a

tdf#132388: reimplement fix for tdf#142487

It will be available in 7.2.6.

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.