Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0047511Openbravo ERPA. Platformpublic2021-08-06 08:502021-09-15 09:25
alostale 
alostale 
normalminorhave not tried
closedfixed 
5
 
PR21Q4 
Core
No
0047511: Entity.getProperty generates too much memory garbage
Profiling JVM object allocation raises there are many byte[] allocations in Entity.getProperty method.

These allocations come from String concatenation to generate an error message in case the requested property does not exist.

Note even the method is not expensive itself, it is invoked many times resulting in the top object allocator.
1. Start recording with JDK Mission Control's Flight Recorder [1]
2. Ie. in POS create 4 time a ticket with 4 product and pay it
3. Check Flight Recorder results.
  -> It warns about byte[] allocation in Allocated Classes section
  -> In Memory details (see attached no-fix.png) check a total of ~250MB byte[] where allocated, checking the stack traces, it can be seen the main contributor for this allocation is Entity.getProperty.


[1] https://www.oracle.com/java/technologies/jdk-mission-control.html [^]
Optimize messages to be generetad only if required. 2 alternatives:

1. Overload Check.isNotNull to support a message Supplier:
  Check.isNotNull(prop, () -> "Property " + propertyName + " does not exist for entity " + this));

2. Do the check null directly in Entity.getProperty

Even alternative 1 reduces a lot the byte[] allocation, lambdas are allocated. Being a method that is invoked all the time, 2nd alternative is more optimal (although a bit dirtier from the code point of view).

Attached image (fix2.png) of the 2nd alternative executing the same steps as described above.
Performance
png no-fix.png (110,330) 2021-08-06 08:54
https://issues.openbravo.com/file_download.php?file_id=16075&type=bug
png

png fix2.png (84,359) 2021-08-06 08:58
https://issues.openbravo.com/file_download.php?file_id=16076&type=bug
png
Issue History
2021-08-06 08:50alostaleNew Issue
2021-08-06 08:50alostaleAssigned To => platform
2021-08-06 08:50alostaleModules => Core
2021-08-06 08:50alostaleTriggers an Emergency Pack => No
2021-08-06 08:50alostaleAssigned Toplatform => alostale
2021-08-06 08:50alostaleTag Attached: Performance
2021-08-06 08:52alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=22980#r22980
2021-08-06 08:54alostaleFile Added: no-fix.png
2021-08-06 08:55alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=22981#r22981
2021-08-06 08:57alostaleProposed Solution updated
2021-08-06 08:58alostaleFile Added: fix2.png
2021-08-06 09:34hgbotNote Added: 0130999
2021-09-15 07:46alostaleSummaryEntity.getProperty generates too memory garbage => Entity.getProperty generates too much memory garbage
2021-09-15 09:25hgbotResolutionopen => fixed
2021-09-15 09:25hgbotStatusnew => closed
2021-09-15 09:25hgbotFixed in Version => PR21Q4
2021-09-15 09:25hgbotNote Added: 0131800
2021-09-15 09:25hgbotNote Added: 0131801

Notes
(0130999)
hgbot   
2021-08-06 09:34   
Merge Request created: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/421 [^]
(0131800)
hgbot   
2021-09-15 09:25   
Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/openbravo [^]
Changeset: 2d8de0958f551e3e17e91019ed70bb05642c754e
Author: Asier Lostalé <asier.lostale@openbravo.com>
Date: 2021-09-15T07:47:07+02:00
URL: https://gitlab.com/openbravo/product/openbravo/-/commit/2d8de0958f551e3e17e91019ed70bb05642c754e [^]

fixes ISSUE-47511: Entity.getProperty generates too much memory garbage

Entity.getProperty, which is invoked all the time, generated a huge
amount of memory garbage just preparing the message to be displayed in
case the requested property does not exist, which is thrown only very
rarely.

It has been optimized by moving the null check from Check.isNotNull to
Entity class and generating the message only when it is actually thrown.

---
M src/org/openbravo/base/model/Entity.java
---
(0131801)
hgbot   
2021-09-15 09:25   
Merge request merged: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/421 [^]