7 Ways to Increase Performance of Python Applications

Search for a command to run...

No comments yet. Be the first to comment.
Some decisions are tough. You need some good reasons to avoid Elm, but you can't just say NO. Here are three decent reasons to avoid Elm for the front-end. Why me? I created a Pluralsight course about the fundamentals of Elm 0.19. Also, I wrote thre...

From Academia to Industry

What is Elm? Elm is a fascinating small programming language for the front-end. Of course, the JavaScript ecosystem is dominating front-end development, with popular tools like React, Angular, Vue and others. Elm is like a domain-specific language fo...

I've been thinking about what are the key points about making Python applications run faster. Performance is a huge topic and there are so many subtle issues, potential traps, conceptions and misconceptions.
IMHO, these are the key points to improve the performance of Python applications.
As the saying goes, you need to measure in order to improve. Otherwise, how would someone even know that any supposed improvement really worked or not? Without measuring, we can just do any placebo fix and declare it's an improvement.
True story: a few years ago, my car's engine was a bit noisy. The mechanic told me: 'look, I have this awesome engine oil which is going to make the engine run silently'. I agreed to do it and I even measured the engine noise with one of those mobile apps that measure noise intensity. After changing the oil, the mechanic looks at me triumphantly and declares: 'Listen to the engine, it's so quiet now'. Indeed, it almost sounded quieter. Just to be sure, I pull out my mobile and start measuring the noise. Guess what: it was the same noise level 😄.
Bottom line: measure performance or else I'll send you to that car mechanic.
Python has various data structures which work best in different scenarios.
Remember the funky big O notation? Well, it's not just some theoretical BS, it really stings when performance matters. You just need to watch out for a few data structures and your Python applications are going to run faster.
This might sound a bit generic, since even using the right data structure is a form of optimization, right? There is more to it. Think about caching: it's relatively easy to implement and it has a dramatic impact on performance. The idea is to collect a bunch of concrete tactics that result in clear performance gains.
Sometimes your Python application might wait for something. Multithreading can improve performance. Still, multithreading has plenty of challenges.
Asyncio is friendlier than multithreading. It's a great choice for IO-bound workloads.
Using more processes enables significant performance improvements, if you can split your workload.
One machine might not be enough, so then just scale from one to more machines. Google does it. For example, use something like Kubernetes which takes care of a lot of the serious issues that occur when working with distributed systems.