eclipse.platform.ui icon indicating copy to clipboard operation
eclipse.platform.ui copied to clipboard

Performance improvement for find & replace all in Batch Mode.

Open mehmet-karaman opened this issue 1 year ago • 7 comments

This is an improvement of the search & replace all in text editors/java editors/xtext editors etc. Instead of replacing all occurrences one by one (and notify document change), it replaces all occurrences at once and then notifies the document change (document.set(..) ).

As this feature is only for users which have huge files in their workspace, I've added the ability to turn this feature on/off. For better reusability I had to refactor the two private methods (asRegPattern, substituteLineBreak) in FindReplaceDocumentAdapter and move them into org.eclipse.jface.text.internal.RegExUtils class as public static methods and adjusted the callees to call the refactored methods.

The batch replace was tested with 20.000 occurrences (Java Editor, around 50% improvement and xtext editor about 40%) .. Opening the Java file in plain text editor improved more than 90%.

mehmet-karaman avatar Sep 13 '24 11:09 mehmet-karaman

@iloveeclipse Do you have time to look into this PR?

mehmet-karaman avatar Sep 13 '24 12:09 mehmet-karaman

Rebased on the Latest master..

mehmet-karaman avatar Sep 17 '24 07:09 mehmet-karaman

I think a document.set() will replace all annotations on the document, too. Can you confirm that bookmarks survive that operation?

szarnekow avatar Sep 17 '24 07:09 szarnekow

Oh you're right.. I will look into this how this works.. Maybe I can find the damage regions and feed it one by one ..

mehmet-karaman avatar Sep 17 '24 09:09 mehmet-karaman

Test Results

 1 815 files  ±0   1 815 suites  ±0   1h 43m 54s :stopwatch: + 13m 25s  7 699 tests ±0   7 471 :white_check_mark: ±0  228 :zzz: ±0  0 :x: ±0  24 258 runs  ±0  23 511 :white_check_mark: ±0  747 :zzz: ±0  0 :x: ±0 

Results for commit e973066e. ± Comparison against base commit a43889de.

github-actions[bot] avatar Sep 17 '24 09:09 github-actions[bot]

@Wittmaxi Thanks for the review. But with this PR i stumbled over the blocker, that all IMarkers are lost.. Tasks, Bookmarks and Breakpoints.. I would be able to move them programmatically after all replaces but from this bundle I don't have an access to IMarkers.. There is much more effort needed than just putting a method which replaces in a string.. Only improvement is what we can do from here just execute the Batch Replace if there are no Annotations in the current open file, otherwise execute the original search and replace..

mehmet-karaman avatar Sep 26 '24 13:09 mehmet-karaman

Only improvement is what we can do from here just execute the Batch Replace if there are no Annotations in the current open file, otherwise execute the original search and replace..

Do we have case with editors without annotations (except plain text edito)? I believe even generic editor (with tm4e) shows expand/collapse regions for supported code?

iloveeclipse avatar Oct 01 '24 11:10 iloveeclipse