Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

[Solved] Browse() vs read() performance

Subscribe

Get notified when there's activity on this post

This question has been flagged
1 Reply
12783 Views
Avatar
Sathors

Hi all.

 

When developing with the API 7, I always prefer the read() instead of the browse() method.
Indeed it seems that a browse fetches all the fields in the table, whereas the read fetches only the few it needs (that are passed to them), thus resulting in a much faster speed.

Actually I never really liked it, because it is easier/more intuitive to use the browse, and the code is nicer.

So what about performance issues in Odoo8?
Is it still recommended to prefer the read() in the API 8?

It would be a shame, moreover now because the browse() in the new API seems so much easier to use.

 

Thanks for your hints,
Cordially,

Nicolas

4
Avatar
Discard
Serpent Consulting Services Pvt. Ltd.

Had blogged it after compilation : www.serpentcs.com/serpentcs-openerp-odoo-difference-of-read-and-browse-calls

Avatar
Sathors
Author Best Answer

I am posting below the answer that Fabien Pinckaers (founder of Odoo) gave me on the Odoo mailing list. Other people also confirmed to me that they did some benchmarks as well, and they found out that browse() result in many cases to be actually faster than read().

 

Hello, Using read() is a bad practice. read() is used for web-services calls but in your own method calls you should always use browse(). Not only, it allows s a better quality of the code, but it's also better for the performance.

- read() calls name_get for many2one fields producing extra SQL queries you probably don't need.
- browse() is optimized for prefetching and auto-load of fields.

 

It's true that browse() may load a few fields you do not need (not all). It prefetches stored fields, because those fields do not costs anything to load in terms of performance.

It's very complex to optimize for performance with read() when the code is complex (involves loops, other method calls). Whereas, with browse(), the framework do the optimization job for you.

Usually, code implemented with read are often with complexities of O(n) or O(n²) as soon as there is loops in your methods. But codes written with browse() are automatically O(1) if browse is called at the beginning of your computations. (not inside loops)

 

Want a small example? Try this code on res.partner:

for company in self.browse(cr, uid, ids, context=context):
    for people in company.child_ids:
        print company.name, people.country_id.code

The above will do 6 SQL queries, whatever the length of ids and number of people/countries. (if IDS>200, he will split into subqueries)
The same code with read(), you will probably end up with 3*len(ids) + 3 queries.

 

Long story short: browse() scale, read() not. (even in v7 or preceding versions)

9
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now