Feature Request: Parallel Processing (Multithreading)
-
No sure why so long time have passed and no implementation of Parallel Processing or Multithreading. is it difficult to implement or what?. i am having 20 core CPU and just one core Notepad ++ is utilizing and taking forever. please update if this is possible or not possible.
-
Parallel processing of what?
A single CPU has enough power to handle your keyboard typing.Most users of Notepad++ do not experience high CPU utilization or long delays. The few that did (lookup the forum) usually found a faulty plugin or wrong usage paradigm that was easy to fix.
Multi threading is not a feature. It is a tool in the hands of the developer to be applied to specific parts of the application. And for most tasks it is far less helpful than people tend to think.
So the question is whether there is a specific task that bothers you. For example: Find in files. For which the answer is: “Yes it is difficult to implement”.
-
-
@gstavi said in Feature Request: Parallel Processing (Multithreading):
Parallel processing of what?
In my humble opinion.I can give you an exemple.
Right now I’m doing a Replace in a file with 1 million lines… the CPU used is at max 13% that is just a single core.
It could speed up a lot of tasks that take like 20-30 minutes to do in daily tasks… that is a lot of save.After all you are doing only that and need it to finish to go ahead… so using the 100% of the CPU should be ideal for any app including a text editor.
We are in 2024 and as things go in terms of CPU cores then I think it is something to be in the plan for that excellent app.
PS. While you are doing these tasks the App UI freezes and the only way to know it is doing the job is looking at the CPU use in Task Manager.
-
@ethpsantos said in Feature Request: Parallel Processing (Multithreading):
Right now I’m doing a Replace in a file with 1 million lines… the CPU used is at max 13% that is just a single core.
It could speed up a lot of tasks that take like 20-30 minutes to do in daily tasks… that is a lot of save.It seems to me very unlikely that multi-threading for tasks like this will ever be introduced to Notepad++. It would be difficult, and probably wouldn’t help nearly as much as you think, since the underlying edit control (Scintilla) is single-threaded.
If you are using Notepad++ daily to do tasks that run for 20-30 minutes without user interaction, it is likely that you can find a better tool for the job. Consider something like sed. I doubt that it is multi-threaded, and it would take you some time to learn how to use it, but it would surely accomplish the sort of task you describe much more quickly.
-
Doing a multi-threaded search and replace isn’t going to be is trivial as yuo think it is. Multithreading works best when the items being processed are not closely related. Unfortunately chunks of text in a single file are actually quite closely related.
For a general replace ‘some text’ with ‘different stuff that will probably be a different length’, you have to ensure that none of the threads overwrite another threads data, so they’ll need to do a lot of synchronisation.
Now it is possible that for your particular case, you could divide the text up into individual sentences and operate on each sentence in parallel (and then tie them all back up into the buffer afterwards).
But that is a very specific usecase, and not applicable to every search and replace by any means.
It’d be a lot of work to do that generally.
It is worth noting that the first thing you should learn about threads is to try and find another way of solving your problem. They are tricky little beasts.
-
@ThosRTanner said in Feature Request: Parallel Processing (Multithreading):
Doing a multi-threaded search and replace isn’t going to be is trivial as yuo think it is
It wouldn’t be too hard (in principle) for Find in Files,
which is likelybut of course that’s not the main thing the OP was talking about. Just spin up N threads to read X files and assign X/N files to each thread.In practice, I’ve seen the source code for the find/replace dialog, and it is filled to the brim with global shared state, and thus potential race conditions. If Notepad++ had automated UI tests, some experienced programmer could be pretty cavalier about tearing out the whole edifice and starting over from scratch, but of course no such UI tests exist and thus I don’t think even a programmer with considerable skill in multithreaded programming could fix this without introducing unacceptable risk of corrupting files while executing a multithreaded Replace in Files action.
There’s another element here, which is ease of debugging. Notepad++ doesn’t have any built-in logging mechanism, and anyone who’s ever tried using an interactive debugger on a multithreaded program knows that log files are the only way to debug those programs without going insane.
-
@nft-3000 said:
No sure why so long time have passed and no implementation of Parallel Processing or Multithreading. is it difficult to implement or what?. i am having 20 core CPU and just one core Notepad ++ is utilizing and taking forever. please update if this is possible or not possible.
and @ethpsantos said:
Right now I’m doing a Replace in a file with 1 million lines… the CPU used is at max 13% that is just a single core.
It could speed up a lot of tasks that take like 20-30 minutes to do in daily tasks… that is a lot of save.Nearly all tools, including Notepad++, are single threaded. However, you can start 20 instances of Notepad++, or nearly any tool, and to have them do things in parallel, if that’s your desire. For Notepad++ you can either:
- Set up 20 separate portable copies and to start them using the
-multiInst
command line argument. This provides the best isolation between your copies so that they don’t step on each other. - Set up one portable copy and have 20 separate settings folders. Start your copies using the
-settingsDir
and-multiInst
command line options. This provides nearly the same level of isolation between the copies. Some plugins, such asNppConverter
seem to ignore-settingsDir
and so this is something you should be alert for when setting up scripts that will be run for each each copy of Notepad++.
NppExec and PythonScript, and probably other plugins, support running a script when Notepad++ is started. That’s how you will get your 20 copies of Notepad++ to do whatever you want as they are started.
As you will have 20 config.xml files you can adjust each of the 20 copies to have a small window on your monitor(s) so that you can view the progress of all 20 copies doing things at once.
- Set up 20 separate portable copies and to start them using the
-
@gstavi said in Feature Request: Parallel Processing (Multithreading):
A single CPU has enough power to handle your keyboard typing.
“640K ought to be enough for anybody”
Only 3 years ago but someone with similar foresight to half a century ago.
There’s always someone there to explain why something hasn’t been implemented yet, rather than questioning “why not?”
Some of Notepad++ users use it as a reverse engineering tool and when running “Find in files” (great feature) which is extremely slow in comparison to even a 10 year old mobile phone (yes lecture me on architectures or if I’m lucky why a reduced instruction-set computer outperforms x86 at this task that’s 10 generations ahead).
The team at Notepad++ are amazing for their contributions and development of this app but comments like yours only stifle development. 8 people boosted up a comment because they don’t need it themselves… So the people who ask for sensible 21st century advancements get pushed to the side.
Your comment started with “Most of us”… I’ll answer that "All of us will benefit from multi-threaded workloads…
If they can support 32-bit builds which next to none of us use a 32-bit computer (which even then they have multiple cores)… Then asking for multi-threading support on a find and replace really isn’t asking a great deal, is it?
-
@ThosRTanner I’ve just achieved multi-threaded find and replace in a simple Powershell script using 1 thread per directory before moving onto the next job.
I think it’s simpler when people don’t try to find reasons for things being harder than they actually are.
Powershell is one of the most primitive “high-level” languages around and it was much faster.
Of course a pretty GUI with better ease-of-use is much more preferrable :)
-
@Harry-Brookes said in Feature Request: Parallel Processing (Multithreading):
I think it’s simpler when people don’t try to find reasons for things being harder than they actually are.
People constantly insist that the single-threaded nature of most core Notepad++ APIs must just be due to sheer laziness on the part of its core devs, and those people have apparently never actually looked at the codebase and tried to understand the issues involved. Refactoring anything in NPP to use multiple threads is (by my estimate) several times more difficult than creating a multithreaded version of the same thing from the ground up.
Notepad++ has a tremendous amount of shared global state, which could only be made compatible with multithreading through extensive use of mutexes, which would then introduce dramatic performance losses in single-threaded use cases (at best) and deadlock (at worst). By the way, have you ever tried to debug a multithreaded program without extensive use of log files? Hahahahaha, good luck.
Find-and-replace in files seems like an embarrassingly parallel operation (or at least one that can be achieved with only one or two mutexes), but the devil is in the details, and as someone who has actually read the source code for Notepad++'s implementation, there are a lot of details there.
EDIT: AFAICT, the simplest way to even begin to implement multithreaded find-in-files in NPP would be to use multiple Scratchtillas (NPP uses
_pscratchTilla
as a lightweight way to run Scintilla operations like find/replace on a file without doing any graphics rendering), and use some simple task-dividing/scheduling algorithm to decide which Scratchtilla works with which file. The scariest problem that I can think of comes when the the Scratchtilla has to report its progress back to the form that shows progress. From my limited experience (I am admittedly a noob to multithreading with GUIs), there seems to be a lot of risk of deadlock whenever multiple threads contend for a lock on a GUI element. And that’s just the tip of the iceberg.