Code Quality Resolves Performance Issue

Performance issues while developing modules

Taking care of Performance issues while developing modules

Introduction

This blog is regarding how to take care of performance problems we face after deploying a multi-feature module, added feature works fine but that also impacts the performance very badly due to bad approach and code.

Every software needs better performance. Code quality on the modules is the key to the better performance of the software. but wrong logic on modules impacts the performance of any software.

Taking care of performance issues while developing modules is important to ensure that the software performs optimally when it is deployed.

Mostly performance issues occurred when the size of the database is large and has a large amount of data.

Sometimes performance issues not occurred when the database is new or the number of records in the database is less but after a few years, the database grows and then a large amount of data is stored on the server at that time performance issues can arise.

Some Reasons for the performance issue

  1. Inefficient Code: If the code is poorly written, it can have a significant impact on performance. This includes issues such as unnecessary loops, large and complex code blocks, and inefficient algorithms.
  2. A wrong approach to achieve big features.
  3. Lack of Re-usability of code.

Points to be kept in mind before starting development.

  • Write efficient and optimised code that is scalable and can handle large data sets. This includes using efficient algorithms, minimising resource usage, and avoiding unnecessary loops and operations.
  • Development should not impact the performance of the database that has a large amount of data.
  • Never search records on code with an empty domain. Always limits records. Search with the proper domain or perform the operation in batches.
  • We can have multiple possibilities/approaches to achieve features, First Identify a better option to achieve, and then start development.
  • Unit Test the module for scalability by simulating large data sets and user loads. This will help in identifying potential performance bottlenecks and areas for optimization.

Database population

  • Odoo offers a 'Database population' that is used to unit test by creating a large amount of data on the database.
  • We can define the size of the attribute _populate_sizes that can be used to create a number of records for a particular object.

Here is an example to create 50K products for the database with the help of the Odoo populate.

# Define _populate_size
class ProductProduct(models.Model):
    _inherit = "product.product"
    _populate_sizes = {"small": 150, "medium": 5000, "large": 50000}
Execute populate for the product.product object
./odoo-bin populate --models product.product --size large -d $DB_NAME

For more details: Odoo Official Document

Split records for performance.

When working with large datasets in a software application, splitting records into smaller chunks can help improve performance by reducing the amount of data that needs to be processed at one time. Here are some ways to split records when needed in performance:

  1. Filtering: Use filtering for relevant records based on the user's search criteria, reducing the number of records that need to be processed and improving the response time.

  2. Batch Processing: Implement batch processing to process large datasets in smaller chunks, reducing the load on the server and avoiding timeout or performance issues.

By splitting records into smaller chunks, you can improve the performance of your software application and provide a better user experience for your users.

For example, there are more than 10K product records existing on the database and we need to export a CSV file with all product details and also the other calculated required data that needs to be added to the CSV columns. To achieve this, it is necessary to manage these kinds of features using split records. We have to generate multiple CSV files in batches with a limit of product records per batch instead of generating a single CSV with all product records.

Code Quality Resolves Performance Issue
BizzAppDev April 25, 2023
Share this post
Sign in to leave a comment
Owl.js with Odoo
Odoo Web Library (Owl) is a modern UI framework enhance the user experience of Odoo application.