🚀 Boost Your Odoo Performance with @lazy_property When working with Odoo, every millisecond counts — especially on heavy models like res.partner or sale.order. That’s where the @lazy_property decorator comes in. 🔹 What is @lazy_property? @lazy_property is a decorator in Odoo (odoo.tools) that allows you to compute a value once per record and reuse it without recalculating during the same request. Think of it as a smart cache for model properties. 🔹 Why should we use it? - Prevents repeated database queries within a single request. - Optimizes performance for expensive calculations. - Keeps the code cleaner (no manual caching logic needed). - Directly improves runtime efficiency 🔹 Where can we use it? Use @lazy_property when: - The value doesn’t change during the request lifecycle. - It requires heavy DB operations or complex calculations. - Example: counting related records, aggregated values, pre-processed settings. 🔹 How can we use it? Please look at the attached image for code snippet: ✅ The first time you access partner.sale_order_count, it runs the query. ✅ Next calls in the same request will use the cached result — no extra queries! 🔹 How does it reduce runtime & improve Odoo experience? - Without @lazy_property: each call executes a new DB query. - With @lazy_property: only one query per record per request. - Result: faster views, optimized API responses, and smoother user experience. 💡 Pro Tip: Don’t overuse it. If the value can change within the same request, avoid caching with @lazy_property. ❓ Open Question Have you already used @lazy_property in your Odoo projects? 👉 If yes, what’s your favorite use case? If not, where do you think it could save you the most performance? #Odoo #OdooDevelopment #OdooTips #EnterpriseSoftware #ERP #BackendDevelopment #SoftwareEngineering #DataProcessing #PerformanceOptimization #OpenSource
I didn’t know Odoo provided a decorator for lazy_property function (from odoo.tools.func import lazy_property). I believe they do the same thing. Definitely adding this one to my toolbox. Thanks!
I can put it directly in a variable and use it , what is the difference?
Love this, Jayank
Thanks for sharing, Jayank
Thanks for sharing
Software Developer at Odoo
1moFrom the example given it looks line you didn't understand the way it works and its purpose. It is not cached per request but for the whipe life of the server. It has even been replaced by `functools.cached_property` in Odoo 19.