Home › Curriculum › Odoo Developer › Performance: N+1, prefetching, aggregates, indexes and profiling
Testing, quality and performance · 16 min · 17–20Performance: N+1, prefetching, aggregates, indexes and profiling
Writing fast ORM code, finding slow requests and queries, indexing and profiling.
In this lesson
- N+1 and prefetching
- Computes, indexes and batching
- Profiling and measuring
Key points
- Iterate recordsets; never search per record in a loop
- _read_group for aggregates; mapped/filtered
- Right dependencies on stored computes; index=True or 'trigram'
- Profile first: Odoo profiler, debug_sql logs, pg_stat_statements, EXPLAIN
Real-world example
A customer statement report took 90 seconds: it searched invoices once per customer inside a loop over 4,000 customers. One search for all open invoices, grouped in a dictionary by partner, brought it to 3 seconds.
Questions and answers
How do you see SQL in logs?
--log-level=debug_sql (development only).
What does odoo-bin populate do?
Generates realistic volumes of test data for performance testing.