#424 Aggressively optimise getLineOfOffset()

closed-accepted
None
5
2012-05-19
2012-05-19
Thomas Meyer
No

getLineOfOffset() is called many times during search-and-replace-all. especially when many matches are found on the same line. aggressively optimise the method.
"if(getLineOfOffsetLine > 0 && getLineOfOffsetLine < lineCount)" is intentional, and doesn't optimise the first line.
with this optimisation in place I get a save of about 3 second for the test file in patch 3527797 (443849: jedit-slow-search-replace-small.txt.zip). Replace "," with ", ".

Results from three consecutive runs:
Old:
12:43:29 [AWT-EventQueue-0] [debug] AWT-EventQueue-0: Call= 1 Avg=39.021.342.152ns
12:45:08 [AWT-EventQueue-0] [debug] AWT-EventQueue-0: Call= 2 Avg=38.666.700.061ns
12:46:20 [AWT-EventQueue-0] [debug] AWT-EventQueue-0: Call= 3 Avg=38.439.786.883ns

New:
13:09:58 [AWT-EventQueue-0] [debug] AWT-EventQueue-0: Call= 1 Avg=35.003.104.998ns
13:11:03 [AWT-EventQueue-0] [debug] AWT-EventQueue-0: Call= 2 Avg=35.455.804.596ns
13:12:03 [AWT-EventQueue-0] [debug] AWT-EventQueue-0: Call= 3 Avg=35.016.101.143ns

Discussion

    • assigned_to: nobody --> jarekczek
     
    • status: open --> closed-accepted
     
  • Pleasant job to apply such a clean patch. r21685. Only extended comments a bit.

     
  • Forgot to mention, that my approximation shows another 20% improvement in search and replace. Usually there will be not so many operations on a single line, but I believe it will still be efficient.