Bug 189456

Summary: Formatter is slow on big files
Product: [Eclipse Project] JDT Reporter: David Audel <david_audel>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: frederic_fusier, jerome_lanneluc, maxime_daniel, philippe_mulet
Version: 3.3Keywords: performance
Target Milestone: 3.3 RC3Flags: frederic_fusier: review+
jerome_lanneluc: review+
philippe_mulet: review+
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Performance tests for formatter none

Description David Audel CLA 2007-05-28 11:22:08 EDT
build 3.3RC2

It take around 20sec to format GenericTypeTest on my computer.

I profile the execution of the format operation.
The format operation last 17sec and 12 sec are spend inside CharOperation#indexOf(char[], char[], boolean, int, int).

The problem could be in Scribe#hasNLSTag() and Scribe#printLineComment() which call indexOf() to search an nls tag from the current position to the the end of the file.
The fact that the file is big and that there is no real nls tag inside could be responsible of the slowness.
Comment 1 Olivier Thomann CLA 2007-05-28 22:34:18 EDT
Created attachment 68989 [details]
Proposed fix

David, could you please let me know if it is faster with this patch?
If yes, I'll request reviews for RC3.
Comment 2 Olivier Thomann CLA 2007-05-29 09:56:41 EDT
Maxime, Jérôme and Frédéric, please review.
If ok, I'll tag it as 3.3RC3.
Comment 3 Frederic Fusier CLA 2007-05-29 10:11:45 EDT
Adding a new performance test suite with one test formatting a big file
(GenericTypeTest.java), here are the results I got:

3.2     15,776.5ms
RC2:    15,779.7ms
patch:   3,586.0ms

So, sounds like a good candidate for global fingerprints :-)
Comment 4 Frederic Fusier CLA 2007-05-29 10:12:19 EDT
Obviously +1 for 3.3 RC3 with previous performance results...
Comment 5 Jerome Lanneluc CLA 2007-05-29 10:50:32 EDT
+1 for 3.3 RC3
Comment 6 Frederic Fusier CLA 2007-05-29 11:00:22 EDT
Here are the results I got when formatting is done on a medium file
(Parser.java: 225176 chars):

3.2     1568.7ms
RC2:    1567.1ms
patch:   684.4ms
Comment 7 Philipe Mulet CLA 2007-05-29 11:02:47 EDT
+1 for rc3
Comment 8 Olivier Thomann CLA 2007-05-29 11:04:59 EDT
Philippe, please review
Comment 9 Philipe Mulet CLA 2007-05-29 11:06:40 EDT
Patch looks good.
Comment 10 Olivier Thomann CLA 2007-05-29 11:12:19 EDT
Released for 3.3RC3
Comment 11 Frederic Fusier CLA 2007-05-29 11:15:08 EDT
Created attachment 69071 [details]
Performance tests for formatter

Add new performance test suite: FullSourceWorkspaceFormatterTests.

This suite has 2 tests:
- testFormatDefault:
    format Parser.java file (225176 chars) ten times
- testFormatDefaultBigFile:
    format big file GenericTypeTest.java (1297242 chars) once

10 measures (ie. start/stop) are done for each test with a warmup of 5 iterations...
Comment 12 Frederic Fusier CLA 2007-05-29 11:46:25 EDT
(In reply to comment #11)
> Created an attachment (id=69071) [details]
> Performance tests for formatter

Released for 3.3 RC3
Comment 13 David Audel CLA 2007-06-01 11:30:20 EDT
Verified for 3.3RC3 using I20070601-0010.

When folding is enabled the code is formatted in the editor after 20 sec.
When folding is disabled the code is formatted after 5 sec.