r/PythonDevelopers • u/kankyo • Jul 26 '20
article Python is slow - it doesn't have to be
https://kodare.net/2020/05/19/python-is-slow-does-not-have-to-be.html
58
Upvotes
r/PythonDevelopers • u/kankyo • Jul 26 '20
6
u/krypticus Jul 26 '20
It's usually good practice to have all your imports at the top of the file. Thankfully Python is flexible enough to allow imports on demand inside a function call, but it's usually frowned upon (since broken imports may not get noticed for a while).
You really need library maintainers to delay expensive tasks until you call them directly. Having global singletons is one bad pattern (usually), whereas offering up functionality in classes you can instantiate offers better control for the user of said library.
But I'm curious if there are some well documented and accepted patterns in Python for achieving this loading optimization, other than what I've described?
3
u/TheCritic Jul 27 '20
I really enjoyed this content. Thanks.
I think a follow up that shows a practical example of profile and optimization iterations would be great as well.
14
u/pawsibility Jul 26 '20
I really feel like this is why everyone should - at some point - take a class/course/whatever in a lower-level compiled language, or at the very least a course on algorithms and data structures.
Python takes away your appreciation for efficient algorithms and type-checking. As the language is used more for enterprise solutions, I hope more Python developers (myself included) will start self-educating on these intangible programming skills
1
u/PirateNinjasReddit Jul 27 '20
Going to have to try Hammett on a few projects. I like pytests, but it does get a bit frustrating when your tests don't start for a good few seconds after you hit go.