Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0033129Openbravo ERPA. Platformpublic2016-06-03 11:142016-06-17 19:38
alostale 
alostale 
normalminoralways
closedfixed 
5
 
3.0PR16Q3 
caristu
Core
No
0033129: unneeded object initialization for DAL insertion
The first time a new DAL object is saved per transaction (typically per request). Some unneeded DAL objects are initialized. This has a performance impact because:

 1. Additional DB queries are executed
 2. Some heap is consumed for those DAL objects. If the request processing is fast, they are quickly made electable for garbage collection, but in any case this makes GC to be invoked more often than needed.
0. Copy the following code somewhere executable (ie. in About.java):

    for (int i = 0; i < 10; i++) {
      AlertRule newAlert = OBProvider.getInstance().get(AlertRule.class);
      newAlert.setName(Long.toString(System.currentTimeMillis()));
      OBDal.getInstance().save(newAlert);
    }


1. set HQL to bebug
2. Execute it and check the log

9169004 [http-8080-3] DEBUG org.hibernate.SQL - select ... from AD_Client adclient0_ where adclient0_.AD_Client_ID=?

9169005 [http-8080-3] DEBUG org.hibernate.SQL - select ... from AD_Language adlanguage0_ where adlanguage0_.AD_Language=?

9169005 [http-8080-3] DEBUG org.hibernate.SQL - select ... from AD_Org organizati0_ where organizati0_.AD_Org_ID=?

9169006 [http-8080-3] DEBUG org.hibernate.SQL - select ... from AD_User aduser0_ where aduser0_.AD_User_ID 
in (?, ?)

9172172 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...
9172173 [http-8080-3] DEBUG org.hibernate.SQL - insert into AD_AlertRule ...


First 4 queries are unnecessary, they are executed to instantiate client, org and user DAL objects.

Use Hibernate proxies for these objects so they don't need to be initialized.
Performance
related to defect 0033126 closed shuehner Avoid select to ad_role during creation of c_import_entry 
Issue History
2016-06-03 11:14alostaleNew Issue
2016-06-03 11:14alostaleAssigned To => platform
2016-06-03 11:14alostaleModules => Core
2016-06-03 11:14alostaleTriggers an Emergency Pack => No
2016-06-03 11:16alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=12311#r12311
2016-06-03 11:20alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=12312#r12312
2016-06-03 11:20alostaleProposed Solution updated
2016-06-03 11:22alostaleTag Attached: Performance
2016-06-03 13:58hgbotCheckin
2016-06-03 13:58hgbotNote Added: 0086986
2016-06-03 13:58hgbotStatusnew => resolved
2016-06-03 13:58hgbotResolutionopen => fixed
2016-06-03 13:58hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/5c3ae208fb2c59fc17b2ced22a80a0c2813ec72f [^]
2016-06-03 14:36alostaleReview Assigned To => caristu
2016-06-03 15:05caristuRelationship addedrelated to 0033126
2016-06-03 15:18caristuAssigned Toplatform => alostale
2016-06-03 15:21caristuNote Added: 0086990
2016-06-03 15:21caristuStatusresolved => closed
2016-06-03 15:21caristuFixed in Version => 3.0PR16Q3
2016-06-17 19:38hudsonbotCheckin
2016-06-17 19:38hudsonbotNote Added: 0087590
2016-12-16 14:15psanjuanRelationship addedrelated to 0032423
2016-12-16 14:15psanjuanRelationship deletedrelated to 0032423
2016-12-16 14:15psanjuanRelationship addedblocks 0032423
2016-12-16 14:15psanjuanRelationship deletedblocks 0032423
2016-12-19 11:08psanjuanRelationship addedrelated to 0032423
2016-12-19 11:09psanjuanRelationship deletedrelated to 0032423

Notes
(0086986)
hgbot   
2016-06-03 13:58   
Repository: erp/devel/pi
Changeset: 5c3ae208fb2c59fc17b2ced22a80a0c2813ec72f
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Fri Jun 03 13:58:10 2016 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/5c3ae208fb2c59fc17b2ced22a80a0c2813ec72f [^]

fixed bug 33129: unneeded object initialization for DAL insertion

  When doing DAL insertions, client, org and user objects were initialized if
  they were not yet in session. This causes unneded DB queries and object allocation
  in memory.

  These objects were used to set mandatory client/org and audit fields.

  This initialization is now prevented by using hibernate proxies instead.

---
M src/org/openbravo/dal/core/OBInterceptor.java
M src/org/openbravo/dal/service/OBDal.java
---
(0086990)
caristu   
2016-06-03 15:21   
Code review + testing OK: extra queries to AD_Client, AD_Org and AD_User are not done anymore.

Verified in pi@5c3ae208fb2c
(0087590)
hudsonbot   
2016-06-17 19:38   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/0dc7be081b1c [^]
Maturity status: Test