impd icon indicating copy to clipboard operation
impd copied to clipboard

impd slows down from 5 blocks per second to 1 block every 2 seconds

Open 825i opened this issue 10 months ago • 7 comments

Sorry for the vague issue title but I have noticed that impd seems to slow down after processing the first minute or so of audio. Why is this? I have a 24-core i9 CPU with 64GB of RAM and a 2TB SSD. Generally it will do the first minute extremely quickly and process up to 5 blocks per second, but then slow down to about 1 block every 2 seconds.

Is there some sort of known bottleneck that I could look at and submit a PR for?

Mind you, I realise the application is designed to run on bash and I am running it in WSL (sorrynotsorry). However, I have given WSL all of my cores, and half my RAM etc. and everything else I run on WSL is lightning fast.

825i avatar Mar 07 '25 19:03 825i

Windows is proprietary software. Proprietary software by design doesn't respect the users' freedom and community. You are not allowed to run such a program as you wish, you can't study how it works and what it does, you can't change it, you can't make and distribute copies of it.

If you run a proprietary program, you put its owner in a position of power over you and your computer. You give them powers to abuse you. Don't allow them to commit injustice.

Tempted by the power to do anything they want on the users' computers, developers of proprietary programs tend to include malicious functionalities. In practice almost all proprietary software is malware.

Windows is proprietary malware and it is not user-friendly. So using Windows is bad for productivity and consequently it makes learning Japanese more difficult for no reason.

https://www.gnu.org/proprietary/malware-microsoft.html

You can install the GNU operating system to regain your freedom. Also read this article if you're in doubt.

tatsumoto-ren avatar Mar 07 '25 20:03 tatsumoto-ren

I am reopening this because after using it on Linux, the exact same situation happens. Tested on Ubuntu LTS 24.02.

Basically the initial audio splicing seems really quick. I have an i9-13980HX 24-Core boosted to 5.1GHz running in max performance mode. Though it seems according to htop this application runs on only 1 core.

That said, I would still be interested to know why the condending process slows down so drastically after the first minute-or-so of audio is processed, to as slow as 2 seconds in between each subtitle chunk.

For example:

These chunks were processed at a speed of about 5 chunks per second.

Extracted internal subtitles.
Processing chunk from 4.9 to 6.51...
Processing chunk from 7.07 to 8.89...
Processing chunk from 9.16 to 14.52...
Processing chunk from 15.54 to 17.65...
Processing chunk from 18.25 to 24.66...
Processing chunk from 25.22 to 27.16...
Processing chunk from 27.84 to 29.45...

But at this stage, it's slowed down to a constant 2 seconds per chunk.

Processing chunk from 1327.81 to 1343.39...
Processing chunk from 1343.78 to 1351.27...

On my machine it takes about 4 minutes per episode from complete start to finish for the condensing process. This is not remotely a complaint. I can live with it taking that long, but for a series of eg. 30 episodes it takes roughly 2 full hours. Is this expected?

825i avatar Mar 20 '25 11:03 825i

Yes, I've noticed that it might take a while to process an episode, but I haven't paid attention to why that is the case. Usually impd runs in the background so I don't notice how much time it takes to process each episode.

My guess is that the farther away the chunk's start position from the beginning of the episode, the more time it takes to seek to that position. And it probably has nothing to do with your processor, it most likely has to do with how fast your hard drive can read data.

There might be a way to cut out all chunks in one go instead of launching ffmpeg many times. We need to investigate.

tatsumoto-ren avatar Mar 20 '25 17:03 tatsumoto-ren

Have you found a solution yet?

tatsumoto-ren avatar Apr 19 '25 14:04 tatsumoto-ren

Yeah I solved this by rewriting impd to support MacOS and using my M4 Macbook Pro. It now takes about 7 seconds per episode 🤷‍♂ which is 34x times faster.

My $7,000 32-core, 4090 Linux PC and $8,500 24-core Linux 4090 laptop can't even touch my M4 Macbook Pro. Both had almost the exact same speed, whether running in WSL (which I first tried) or running directly on Linux.

I re-wrote the impd script to be compatible for Apple Silicon MacOs and it's flawless now. Takes about 1 minute and 20 seconds to do 13 episodes. Previously that would have taken me over an hour.

Here it is in action: https://github.com/user-attachments/assets/2d43ac4e-e96e-4cd4-80d4-c5e589524a03

Let me know if you want me to share the new impd. I remember you had some reservations about non-free OSes.

825i avatar Jun 20 '25 02:06 825i

Let me know if you want me to share the new impd.

Yes, please! I would like it to work on a free OS though, so hopefully we can make it cross-platform. Make a pull request so the changes can be compared.

tatsumoto-ren avatar Jun 20 '25 06:06 tatsumoto-ren

Let me know if you want me to share the new impd.

Yes, please! I would like it to work on a free OS though, so hopefully we can make it cross-platform. Make a pull request so the changes can be compared.

https://github.com/Ajatt-Tools/impd/pull/17

825i avatar Jun 21 '25 09:06 825i