Sublime Forum

"Replace All" is very slow when working on very long single lines

#1

TLDR at the end.

Hi everyone,

i came across a strange behaviour today.
I was working with a file that had just one very long line.
Text on this line is separated by semicolons.
I wanted to replace all semicolons with a newline and edit some of the lines before finally replacing all newlines with a semicolon again.
So i selected one semicolon and used ALT+F3 to select them all - pressed return and … nothing.
Sublime Text froze and i killed it after a minute.


The File we are talking about is around 600 kb and (after replacing all semicolons with newlines) has around 18000 Lines with ~30 characters each.
A line looks like this: attribute1 : 12345 : System.Int32
and so the very long line looks like this :
attribute1 : 12345 : System.Int32 ; attribute2 : 0: System.Int32 ; attribute3 : 555: System.Int32 …


So after restarting sublime i tried “Replace All” with regular expressions to convert all ‘;’ -> '\n’
This also seemed to do nothing and Sublime was just frozen an unusable but i decided to let it run and it took a little over 2 minutes to complete.
While this was happening i did a quick
tr ‘;’ ‘\n’ < file1.txt > file1_split.txt
to see if there was something fishy with the file but this completed in a fraction of a second and yielded the desired result.
So when Sublime finally caught up i changed the lines i intended to change and wanted to replace all newlines with a semicolon again.
And of course “Replace All” took over 2 minutes to complete - again.
By that point i was questioning my system so i restarted sublime created a random 18000 Line file by duplicating lines and used CTRL + A to select all -> CTRL SHIFT L to get a cursor on every line and added a semicolon to the end of every line - this took around 2 seconds. Using replace all on this file to replace all semicolons with dollar signs $ took less than a second.
But then i tried to replace all newlines with a semicolon and things broke down again taking around 2 minutes to complete.

I found another strange behaviour:
In the File with 18000 lines i can replace single or multiple characters on all 18000 lines very fast (as long as i don’t touch the newline \n)
If i try to do the same replacement on the file with the very long single line (i am not inserting a newline this time) everything breaks down again.
In fact - just selecting all semicolons in the very long line with ALT + F3 slows sublime down significantly.

Everything was tested on 2 different Systems (both WIN 10) and is easily reproducable


TLDR:

  1. I have a file containing a very long line with around 600000 characters.
  2. Every ~30 characters there is a semicolon.
  3. When i try to replace the semicolons with newlines - Sublime hangs for 2+ minutes before completing.
  4. When i try to replace all newlines with semicolons again - Sublime hangs again for 2+ Minutes.

Observations:

  • Working on a single long line with either Replace All or with multiple (18000) cursors is almost impossible. (regardless if the change involves newlines or not)
  • After splitting the file into 18000 lines the performance of replace all and multiple cursons is normal again. (as long as it does not involve adding or removing newlines)
  • When converting all newlines of a 18000 line file to semicolons it seems to make a difference whether each line contains a bunch of spaces or not
1 Like

#2

it’s fairly well known that long lines can cause lots of lag in ST currently


it can also make a difference whether word wrap is enabled or not IIRC

0 Likes

#3

Thanks for this,

i did not check the github issues like i should have.
This is exactly what i experience so i will just deal with it for now.

-B

0 Likes

#4

In addition to other suggestions, if you haven’t tried this already set the syntax to “Plain Text”. Although Sublime leave a lot to be desired with respect to large files and long line handling, switching off syntax colouring can significantly improve performance.

:slight_smile:

0 Likes