Bug 461710 - ConfigurableLineTracker has poor complexity (quadratic in contents length)
Summary: ConfigurableLineTracker has poor complexity (quadratic in contents length)
Status: CLOSED DUPLICATE of bug 545252
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.4.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2015-03-09 09:23 EDT by Per Mildner CLA
Modified: 2019-08-27 06:26 EDT (History)
3 users (show)

See Also:


Attachments
A naive alternative implementation of ConfigurableLineTracker (5.44 KB, text/plain)
2015-03-09 09:23 EDT, Per Mildner CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Per Mildner CLA 2015-03-09 09:23:16 EDT
Created attachment 251407 [details]
A naive alternative implementation of ConfigurableLineTracker

org.eclipse.jface.text.ConfigurableLineTracker.nextDelimiterInfo(String, int) uses (linear time in contents length) TextUtilities.indexOf(String[], String, int), which makes ConfigurableLineTracker.set(String text) quadratic in the length of text.

The problem is that TextUtilities.indexOf() always looks through the entire remaining text, which ensures that ConfigurableLineTracker.set(String) looks at the entire text for each line in the text, which makes it quadratic in the length of the text in the worst (and common case) where the number of lines is linear in the length of the text.

Informal measurements shows that ConfigurableLineTracker.set() takes more than a minute for a 10000 line, 200k length char string, making it 2000 times slower than DefaultLineTracker. Making the input ten times larger (in number of lines and text length) makes the slowdown ten times worse.

This makes ConfigurableLineTracker uselessly slow, also for not very large documents.

An informal reimplementation (attacked) that just calls text.startsWith(delim,index) for each valid line delimiter at each text index, shows linear time performance, and a slowdown less than ten compared to DefaultLineTracker. This suggests that some very simple replacement for (or re-implementation of) TextUtilities.indexOf() would suffice. This also suggests that the major problem with TextUtilities.indexOf() is not the ambitious ideas mentionend in bug 96951.
Comment 1 Dani Megert CLA 2015-03-17 07:38:51 EDT
Can you provide a performance test for that?
Comment 2 Per Mildner CLA 2015-03-17 07:43:56 EDT
There are performance test-code together with the naive alternative implementation in the attachment I provided. Is that enough? I know nothing about how tests "really" should look in order to fit the Eclipse testing infrastructure.
Comment 3 Dani Megert CLA 2015-03-17 08:56:00 EDT
(In reply to Per Mildner from comment #2)
> There are performance test-code together with the naive alternative
> implementation in the attachment I provided. Is that enough? I know nothing
> about how tests "really" should look in order to fit the Eclipse testing
> infrastructure.

The test should be a JUnit test and both, the test and the ConfigurableLineTracker should be attached as a patch. Ideally you keep the old iplementation so that the test can show the benefit.
Comment 4 Per Mildner CLA 2015-03-17 08:59:52 EDT
That was what I feared. I do not know enough to create a JUnit test for this.

(and I do not know how to create reliable timing tests in any testing framework)
Comment 5 Thomas Wolf CLA 2019-08-27 06:26:28 EDT
Fixed in bug 545252.

*** This bug has been marked as a duplicate of bug 545252 ***