Bug 443014 - A big number of constants in files yields a huge slow down
Summary: A big number of constants in files yields a huge slow down
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PHP UI CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-01 09:40 EDT by Laurent Lyaudet CLA
Modified: 2020-05-14 11:38 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent Lyaudet CLA 2014-09-01 09:40:32 EDT
Hi,

I work with many big PHP files (5k-20k lines) but only with one I have a huge slowdown when I try to edit it.
I noted that in that file we defined a class with 136 constants defined.

I made a simple test script to reproduce the slowdown:
<?php

$sTest = "<?php class CTest{\n";
for($i = 1; $i < 2000; ++$i){
$sTest .= "const ICONST$i = $i;\n";
}

$sTest .= "function test(){}\n";

$sTest .= "} ?>";
file_put_contents('CTest.php', $sTest);

?>

This test script will generate a PHP file with 2000 constants.
Add the file CTest.php to your PHP project in Eclipse.
(Maybe build the project.)
If you try to type something in the test method, you will experience a huge slowdown.

Let me know if I can help further.

Best regards,
   Laurent Lyaudet
Comment 1 Dawid Pakula CLA 2014-09-01 10:19:01 EDT
Hi,

did you test it on 3.3.1 development snapshot [1]? This build have some improvements for large files/projects.

I cannot reproduce your problem.

[1] - http://download.eclipse.org/tools/pdt/updates/3.3-nightly/
Comment 2 Michal Niewrzal CLA 2014-09-01 15:15:51 EDT
I was able to reproduce it with latest version. To trigger the slowdown Outline view must be visible. I also clicked few times in Outline elements. Typing and scrolling is almost impossible.
Comment 3 Michal Niewrzal CLA 2014-09-01 16:34:11 EDT
Problem is probably caused by code from PHPContentOutlineConfiguration.getSelection():

...
Widget testFindItem = viewer
		.testFindItem(lastSelection);
if (testFindItem == null) {
	viewer.refresh();
}
...

Removing this part makes file usable. After opening file there is a glitch for a moment, but after that file can be used normally. This code was introduced in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=321228
Comment 4 Dawid Pakula CLA 2014-09-02 08:39:36 EDT
(In reply to Michal Niewrzal from comment #3)
> Removing this part makes file usable. After opening file there is a glitch
> for a moment, but after that file can be used normally. This code was
> introduced in
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=321228

This code was required to keep selection in outline while writing. Maybe now will be possible to remove these lines.

Michal, did you reproduce it on windows or on another system?
Comment 5 Michal Niewrzal CLA 2014-09-02 15:55:42 EDT
I'm not sure if this code should be removed. I just pointed place responsible for problem:) Tomorrow I will look at it more carefully. 

I reproduce it under Linux x64.
Comment 6 Michal Niewrzal CLA 2014-09-05 11:49:28 EDT
This patch should remove following issues (root of the problem):
* Every change in editor that was changing model was starting refresh for every previously opened editor with Outline view
* Every change in editor that was changing model was refreshing whole Outline view

There are still some performance issues when file with many (~2000) functions/classes is saved, but I will create separate bug for this problem.

Patch proposal: https://git.eclipse.org/r/#/c/32793/
Comment 8 Laurent Lyaudet CLA 2014-09-08 05:57:46 EDT
Thanks for the patch Michal.
It corrects the slowdown when I type something.
However, there is still a slowdown when I save the file CTest.php after edit (if I save another file that is opened in another tab I have no slowdown).
This slowdown is made of the following sequence :
file save action(Ctrl+S), 
freeze for 2-3 seconds (you can still move the cursor but you cannot click something) then the blue circle "something in progress" appears for 7-6 seconds,
freeze for 1-2 seconds then the blue circle appears for 6-5 seconds,
freeze for 2-3 seconds then the blue circle appears for 8-7 seconds.
I assume these 3 consecutive freezes corresponds to 3 distinct process triggered by the file save action.

There must be some process with complexity \omega(n^2) or worse (where n is the number of constants in the file) that is triggered.
Maybe it can be improved to obtain O(n) or O(nlog n) complexity.
If you can find this process(es), I may help.

Best regards,
   Laurent Lyaudet
Comment 9 Michal Niewrzal CLA 2014-09-08 06:26:35 EDT
Thanks for checking my patch Laurent. Problem with saving should be resolved when patch from https://bugs.eclipse.org/bugs/show_bug.cgi?id=443468 will be merged:) I dived this problem into smaller packages.
Comment 10 Sylvia Tancheva CLA 2015-05-22 03:54:32 EDT
So if the slowdown is fixed, and there is another bug about the save freeze can we close this one?
Comment 11 Michal Niewrzal CLA 2015-05-22 04:01:04 EDT
Closed.