Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
22.01.01, Upcoming Branch
-
None
-
None
Description
Here is the detailed information about the things I am working on for performance optimization in our OFBiz code.
1.) Downsize Accessibility Scope
I've tried to downsize accessibility scope of classes, interfaces, abstract class, declared member variables, enumerations, methods, and constructors to as minimum as possible as per OFBIz current implementation, still there is a lot of scope for improvement but it would require changes at the granular level. I've used this as my reference point. example:
public void noteKeyRemoval(UtilCache<K, V> cache, K key, V oldValue);
void noteKeyRemoval(UtilCache<K, V> cache, K key, V oldValue);
2.) Using Lambda Expressions
Then tried to use lambda expressions on simple functional work to leverage implicit type of coding an example:
Map<String, String> initParameters = new LinkedHashMap<>(); for (Element e : initParamList) { initParameters.put(e.getAttribute("name"), e.getAttribute("value")); }
Map<String, String> initParameters = initParamList.stream().collect(Collectors.toMap(e -> e.getAttribute("name"), e -> e.getAttribute("value"), (a, b) -> b, LinkedHashMap::new));
Some of the key benefits of using lambdas will introduce Functional style over Imperative style, we can use method referencing, usage of aggregate operations, and it will help developers to write memory efficient code.
3.) Using Type Inference
Java uses type inference so to make code lightweight I've updated code constructs as shown in the example for more on this refer this article.
Map<String, ? extends Object> systemProps = UtilGenerics.<String, Object> checkMap(System.getProperties());
Map<String, ?> systemProps = UtilGenerics.checkMap(System.getProperties());
4.) Use of single quote for character
There is a significant usage of <"Single Character"> in the codebase for example:-
throw new GenericConfigException("Error opening file at location [" + fileUrl.toExternalForm() + "]", e);
throw new GenericConfigException("Error opening file at location [" + fileUrl.toExternalForm() + ']', e); "]"
"]" is comparatively slower than ']' Java internally uses Flyweight Design pattern to create String literals so for every call it will not create a new Object and used an existing one this will improve performance to some extent a study can be seen on this page.
5.) Updated Variable Declaration
Lastly, some of the variable declarations are updated this doesn't create a huge difference but helps JVM at the from implicit conversion.
private long cumulativeEvents = 0;
private long cumulativeEvents = 0L;
Based on above findings, I have done some code improvement and provided following patches.
And need community help for reviewing these changes.
Kindly provide any improvements or suggestion you have in mind
P.S. Apart from this I am also working on performance matrix and will share it soon.
Attachments
1.
|
Refactoring Variable Scope for org.apache.ofbiz.base package | Patch Available | Unassigned | |
2.
|
Refactoring Variable Scope for org.apache.ofbiz.catalina.container | Patch Available | Unassigned | |
3.
|
Refactoring Variable Scope for org.apache.ofbiz.common | Patch Available | Unassigned | |
4.
|
Refactoring Variable Scope for org.apache.ofbiz.datafile | Patch Available | Girish Vasmatkar | |
5.
|
Refactoring Variable Scope for org.apache.ofbiz.entity | Patch Available | Unassigned | |
6.
|
Refactoring Variable Scope for org.apache.ofbiz.entityext | Patch Available | Girish Vasmatkar | |
7.
|
Refactoring Variable Scope for org.apache.ofbiz.minilang | Patch Available | Girish Vasmatkar | |
8.
|
Refactoring Variable Scope for org.apache.ofbiz.base.start | Patch Available | Unassigned | |
9.
|
Refactoring Variable Scope for org.apache.ofbiz.security | Patch Available | Girish Vasmatkar | |
10.
|
Refactoring Variable Scope for org.apache.ofbiz.webapp | Open | Girish Vasmatkar | |
11.
|
Refactoring Variable Scope for org.apache.ofbiz.service | Open | Girish Vasmatkar |