Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello โ I'm @olemoritz on Twitter.
Pythonista edit mode very very slow with a big script?
-
I'm busy to write a very big script (at least for me ๐ ) of 2000 lines and the edit mode seems to become very very slow, sometimes 1 second between two keys. if I type a word, The keys are stacked and I see the keys, one by one, in gray on the keyboard during one second before to be "taken" and displayed.
What could I do to avoid this problem?
Thanks for help. -
Break you single large script into multiple smaller scripts?
-
Thanks for the idea, I'll try but I've to think how to split because I've a lot of subs (def) which are used by other ones etc..
I really don't know how Pythonista functions when the script is executed. -
I am not sure if this helps. Anyway here are some suggestions.
- Try edit.py in stash
- convert to .txt extension, edit and then convert back to .py.
- If you have large blocks of data, move them to separate file and use ast.literal_eval or json.
- If you do not have globals inside the functions, it may be very easy to move them to other files (from file1 import * should work)
- If you have global variables, try to encapsulate them in classes/
-
Thanks, I'll have a look next week, now it's time for ๐บand๐ท
What is very strange is that editor is not slow always but, I think, not sure, that this occurs more after having tested my script...Is it possible that something stays in memory?
I also want to have only one file because I write this script for a friend who has a little company, in the real world ๐
The first process of my script xxx.py is to check, via FTP, on the Windows PC (or Mac) of my friend is there is a file xxx.Vnnnn with Vnnnn bigger than a variable of my script, called version (obvious, isn't it?). If yes, my script gets this file, rename the current xxx.py into xxx.old and rename the xxx.Vnnnn into xxx.py, and starts it (this part not yet tested, in the worst case, I'll display an alert asking the user to restart the script).
In other words, my script installs automatically an eventual new version. -
That's interesting, I'm busy writing a ~2000 line script with no sign of poor performance in the editor ยฏ\_(ใ)_/ยฏ What device are you using?
-
iPad mini 4, but, as I said, I'm asking me if the problem could not come from the previous run of my script, perhaps "using" too much memory?
-
Is it possible you have not closed your ftp connections? Open sockets, running threads, etc can lead to this kind of slowness if you have run your script many times. Also, if you use
logging
, be sure that your logging recipe checks for existing handlers, and deletes them. The standard logging recipes often assume a commandline usage, such that you set up the handlers everytime. But then if you run your script 10 times, you get 10 handlers that slow things down.Similar problems if you have a Thread that is checking something at wome interval, you might have forgotton to kill the thread. In that case, you might end up with a bunch of threads tryng to clobber the server.
-
Hi @JonB, I don't use any logging and I don't have any "continuous" thread, BUT I forgot to add a FTP.close () line...
So, perhaps it is the reason...
Now, it is corrected and I'll see during my next code modifications if the problem stays.
Anyway, thanks a lot for your (always) excellent advices. -
@cvp In general (not sure if this applies in your case), one thing to watch out for with regards to editor performance is the length of your lines. You'll want to keep them reasonably short because long lines cause performance issues in the syntax highlighter. A common reason for long lines would be embedded dict/list literals. Adding some line breaks usually improves performance.
-
Thank you for worrying about my questions, and also for your marvelous application!
I have only one big line with a list of all colors names (copied from a little script of @Phuket2 ). When you say that long lines could slow sown the editor, do you mean that the editor could be slow all the time if the script contains long lines or only when editing a long line?Anyway, since I close my FTP, as adviced by @JonB (Thanks to him also), I didn't meet this slowness...
-
Yes, I think long lines have some effect on performance even if they are not visible. Try breaking down the long line and see if that helps. If you're too lazy to do it yourself, copy it and run
clipboard.set(clipboard.get().replace(",", ",\n"))
. That adds line breaks after each comma. -
Thanks also to help me.
As I said, the problem does not occur any more (actually) since I added the FTP.close() line and I only have one long line.
Now, I only want to know if Editor could slow down even when editing another line or only when editing the long line... -
@cvp said:
Now, I only want to know if Editor could slow down even when editing another line or only when editing the long line...
Usually, the slowdown should only occur when editing the long line, or the line before/after it.
-
Ok, understood
That wasn't my case, I had slowness everywhere in my script, not only on the only one long line.
Thus, it seems that my missing FTP.close() was the real reason.
Anyway, Thanks to @omz, @JonB and @dgelessus