Sublime Forum

Windows freeze when searching long text files with regex

#1

I’m trying to use a regex to match lines that don’t contain a certain string, like this:
^((?!word).)*$
When I use this on my text file (3 million lines aprox) not only does Sublime freeze, but my entire OS, I have to force restart my computer. I use every Sublime setting on default, and noticed that when I search files, it only uses one CPU core, so I don’t think the OS freeze has to do with all my computer resources being used.
I also noticed that this starts happening on my PC on files larger than 3million lines. Less than that and it seems to work fine, and it doesn’t even slow down the rest of Windows while doing it.

I know the task may be too heavy to handle for Sublime, but it shouldn’t crash my whole system while trying to do so.

I’m using Sublime 3 bulid 3314 on Windows 7 64-bit with an i7 4790k and 16GB RAM.

Thanks

0 Likes

#2

Firstly, have you disabled “Highlight matches”? It’s the button to the left of the search field. If that doesn’t help, try the following:

  1. Instead of trying to match every line not containing a certain string, which is really labour intensive on large files, you could instead match every line containing the string, then invert the selection.
  2. Along the lines of (1), but instead of inverting the selection, delete/cut all the lines found, then select all, CnP what’s left.

The above may help because the approach you’re taking will create a huge amount of multiple selections / cursors which could be contributing to the problem. In the above approach, you’ll create far fewer regions, since any lines not matching will end as a single selection instead of multiple selections.

These are alternatives that you could try, but as you say, Sublime shouldn’t crash let alone bring down your system. Probably the system is going ballistic with eating RAM, which then causes huge swapping on your system, which is making the system unresponsive. If you want to investigate a little and post some feedback, open the task manager and keep an eye on memory usage when you’re doing this operation. If the task manager doesn’t freeze and you set the Sublime process priority to below_normal, things may be more responsive allowing you to see more of what’s going on.

:slightly_smiling:

1 Like