# Should create\_uid/write\_uid use lazy loading?

**URL:** <https://discuss.tryton.org/t/should-create-uid-write-uid-use-lazy-loading/2458>\
**Category:** Developer\
**Created:** [March 17, 2020, 12:16am UTC](https://discuss.tryton.org/t/should-create-uid-write-uid-use-lazy-loading/2458 "2020-03-17T00:16:05Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [March 24, 2020, 7:09pm UTC](https://discuss.tryton.org/t/should-create-uid-write-uid-use-lazy-loading/2458/15 "2020-03-24T19:09:10Z")

</div>

> [@albert](#):
>
> I don’t think it’s worth trying to reproduce exactly the same performance improvement. +30% is already a huge difference and you can easily reproduce such a gain in lots of places if you have enough records and m2o fields in the model (although create\_uid/write\_uid are already enough to see the difference).

I can not reproduce your performance on latest trunk. I’ve created a proteus script (see below) to create 200 products and add a shipment which recives 4 units of one of them. I’ve run on a postgresql database with stock, sale, stock\_lot and production modules activated. Here are my results:

With eager loading:

```
Shipment created 0:00:07.425063
Shipment received 0:00:02.891001
Shipment done 0:00:01.724375

```

With lazy loading:

```
Shipment created 0:00:06.377097
Shipment received 0:00:02.791547
Shipment done 0:00:01.463134

```

Here is the script:

```python
import datetime                                                                
from decimal import Decimal                                                    
                                                                               
from proteus import Model, config                                              
                                                                               
config.set_trytond()                                                           
                                                                               
Product = Model.get('product.product')                                         
products = Product.find([])                                                    
if not products:                                                               
    print('Creating products')                                                 
    Uom = Model.get('product.uom')                                             
    unit, = Uom.find([('symbol', '=', 'u')])                                   
    Template = Model.get('product.template')                                   
    templates = []                                                             
    for i in range(200):                                                       
        template = Template()                                                  
        template.name = 'Product %s' % (i + 1)                                 
        template.type = 'goods'                                                
        template.default_uom = unit                                            
        template.list_price = Decimal(0)                                       
        product, = template.products                                           
        product.code = 'PROD%s' % (i + 1)                                      
        product.cost_price = Decimal(0)                                        
        templates.append(template)                                             
    Template.save(templates)                                                   
    products = Product.find([])                                                
                                                                               
ShipmentIn = Model.get('stock.shipment.in')                                    
Location = Model.get('stock.location')                                         
warehouse_loc, = Location.find([('code', '=', 'WH')])                          
Party = Model.get('party.party')                                               
party, = Party.find([], limit=1)                                               
                                                                               
start = datetime.datetime.now()                                                
print('Creating shipment')                                                     
shipment = ShipmentIn()                                                        
shipment.supplier = party                                                      
for product in products:                                                       
    move = shipment.inventory_moves.new()                                      
    move.from_location = party.supplier_location                               
    move.to_location = shipment.warehouse.input_location                       
    move.product = product                                                     
    move.quantity = 4.0                                                        
    move.unit_price = product.cost_price                                       
shipment.save()                                                                
print('Shipment created', (datetime.datetime.now() - start))                   
start = datetime.datetime.now()                                                
shipment.click('receive')                                                      
print('Shipment received', (datetime.datetime.now() - start))                  
start = datetime.datetime.now()                                                
shipment.click('done')                                                         
print('Shipment done', (datetime.datetime.now() - start))     

```

---

_[View the full topic](https://discuss.tryton.org/t/should-create-uid-write-uid-use-lazy-loading/2458)._
