Bug 165918 - Quadratic complexity when loading a document with lots of bookmarks and lots of tables
Summary: Quadratic complexity when loading a document with lots of bookmarks and lots ...
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:25.8.0 inReleaseNotes:25.8
Keywords: perf
Depends on:
Blocks:
 
Reported: 2025-03-26 16:12 UTC by Mike Kaganski
Modified: 2025-04-18 15:14 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
A large number of small tables with bookmarks (9.16 MB, application/vnd.oasis.opendocument.text)
2025-03-26 16:12 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2025-03-26 16:12:50 UTC
Created attachment 200025 [details]
A large number of small tables with bookmarks

Attached is the following ODF markup repeated 20 000 times:

   <table:table>
    <table:table-column/>
    <table:table-column/>
    <table:table-row>
     <table:table-cell office:value-type="string">
      <text:p><text:bookmark-start text:name="Bookmark 1"/>abc<text:bookmark-end text:name="Bookmark 1"/></text:p>
     </table:table-cell>
     <table:table-cell/>
    </table:table-row>
    <table:table-row>
     <table:table-cell/>
     <table:table-cell/>
    </table:table-row>
   </table:table>
   <text:p/>
   <text:p/>

(the index of the bookmark increments each time). It takes significant time to open; and that time depends on the repeat count in a non-linear way, even when opening the document in hidden mode, e.g. using code like this:

  prop = new com.sun.star.beans.PropertyValue
  prop.Name = "Hidden"
  prop.Value = true 'create hidden
  ticks = GetSystemTicks
  doc = StarDesktop.loadComponentFromURL(ConvertToURL("path/to/tableWithBookmark_20000.fodt"), "_default", 0, array(prop))
  ticks = GetSystemTicks - ticks
  MsgBox ticks
  doc.close(True)

E.g., on my system, limiting the document to 5000 copies gives times around 1940 ticks; 10000 copies take ~2390 ticks; 20000 copies take ~5790 ticks; 40000 copies need ~17700 ticks.

The part of loading procedure that creates the non-linear complexity needs optimization.
Comment 1 Mike Kaganski 2025-03-26 16:24:03 UTC
https://gerrit.libreoffice.org/c/core/+/183348
Comment 2 Commit Notification 2025-03-27 06:53:23 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

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

tdf#165918: Avoid bookmarks correction when removing temporary nodes

It will be available in 25.8.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.