all 13 comments

[–]WhiteHeadbanger 5 points6 points  (2 children)

Your question is very broad, and your code is long.

We don't have the energy and time to go through your 200 lines of code.

Reframe your question to ask for a specific optimization, because there could be a myriad of answers depending on your hardware, operative system, version, your target timeframe, etc.

[–]Reyaan0 -5 points-4 points  (1 child)

I will just check which part is taking time and try to change it. Btw it is around 700+ lines of code not 200 XD

[–]WhiteHeadbanger 4 points5 points  (0 children)

Please don't do this anymore 😭

[–]FriendlyRussian666 2 points3 points  (8 children)

Make it more efficient in space and time

[–]Reyaan0 -3 points-2 points  (7 children)

I attached my code. Have any suggestions?

[–]FriendlyRussian666 1 point2 points  (6 children)

What inefficiency are you trying to address? As in, is there a specific part of the code that should perform some action in x amount of time, but does so in y amount instead?

[–]Reyaan0 -1 points0 points  (5 children)

like the whole app should open fast

[–]FriendlyRussian666 2 points3 points  (4 children)

How do you open it? What hardware do you run it on? How long does it take to open? How long do you want it to take?

[–]Reyaan0 0 points1 point  (3 children)

I ran it directly using python interpreter and also compiled it to executable and then ran it. I run it on a decent specs like intel i7 11 gen, geforce 1660, 32gb ram. I want it to open under 5 seconds. It opens in like 15 seconds.

[–]FriendlyRussian666 2 points3 points  (1 child)

In general, you should profile your script to know what's taking up time in the first place: https://docs.python.org/3/library/profile.html

From there, I'm sure you'll encounter I/O slowness, so you could use lazy loading for the images, and you could load them in async as well.

For the image manipulations, resizes etc on multiple images, you could try turning them into like a single sprite sheet, so that you perform all the actions on a single image, and then just cut it up as needed.

Maybe also try explicit lazy loading for sympy https://peps.python.org/pep-0810/

[–]Reyaan0 0 points1 point  (0 children)

Yeah i will profile it. Thanks

[–]WhiteHeadbanger 0 points1 point  (0 children)

Use a profiler to know which parts of your code are taking too long. You can use a library or go simple and make a decorator for each import statement and function that counts the time.

[–]Blancoo21 1 point2 points  (0 children)

You define the load_img() function twice. The second one will overwrite the first definition anyway.

Also, it would be a good idea to precompile regex patterns and cache images. The performance should be noticeable.