Avoiding performance bottlenecks

Over the last few sections, we took a look at the different ways we can profile our application for different kinds of performance bottlenecks that may involve slowdowns to memory leaks. But once we're aware of these issues and why they're happening, what other options do we have to prevent them from occurring again?

Fortunately, we have a couple of helpful guidelines that may help prevent performance bottlenecks or can limit the possible impact of these bottlenecks. So, let's take a look at some of these guidelines:

  • Choosing the correct design patterns: Design patterns are an important choice in the application. For example, a logging object doesn't need to be reinitialized in every submodule of the application and can easily be reused as a global object or a shared object. Making a logging class a singleton can help us in this.
  • Cleaning up the objects as soon as they go out of scope: As a developer, we need to take care of cleaning up the objects as soon as they go out of scope. One of the most basic mistakes that happens during development is keeping the objects in a list or dictionary to track them and later forgetting to clean them up. This causes the memory usage to grow.
  • Using native libraries: Python allows the use of native extensions. These are the extensions that have been compiled internally and are optimized for the machine they are running on. This provides a huge boost in the performance of an application in comparison to using the methods that need to be converted into bytecode every time they are supposed to be used.
  • Monitoring the Garbage Collector: In some of the applications that are allocating a large chunk of objects, one of the bottlenecks that may happen is due to the runs of the garbage collector. In these applications, the garbage collector needs to be monitored and optimized where required, so that we can avoid the slowdowns it may cause.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.34.197