[
https://issues.apache.org/jira/browse/OFBIZ-10343?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Pradhan Yash Sharma updated OFBIZ-10343:
----------------------------------------
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|https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html]
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);Limiting the scope of
the method from public modifier to package level.
*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|https://stackoverflow.com/questions/2078978/functional-programming-vs-object-oriented-programming],
we can use [method
referencing|https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html],
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|https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.htmlv].
- 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 comparativlelly slower then ']' 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 performace to some extend an
study can be seen on
[this|https://stackoverflow.com/questions/24859500/concatenate-char-literal-x-vs-single-char-string-literal-x]
page.
*5.) Updated Variable Declaration*Lastly some of the variable declaration is
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 improvents or suggestion you have
in mind :) # [OFBIZ-10344] Refactoring Variable Scope for
org.apache.ofbiz.base package
# [OFBIZ-10345] Refactoring Variable Scope for
org.apache.ofbiz.catalina.container
# [OFBIZ-10346] Refactoring Variable Scope for org.apache.ofbiz.common
# [OFBIZ-10347] Refactoring Variable Scope for org.apache.ofbiz.datafile
# [OFBIZ-10348] Refactoring Variable Scope for org.apache.ofbiz.entity
P.S. Apart from this I am also working on performance matrix and will share it
soon.
was:Method and Variable access modifiers can be narrowed down to private
access modifier. Set assignments to type variables. Usage of the implicit style
of coding.
> Refactoring Variable Scope
> ----------------------------
>
> Key: OFBIZ-10343
> URL: https://issues.apache.org/jira/browse/OFBIZ-10343
> Project: OFBiz
> Issue Type: Improvement
> Components: framework
> Affects Versions: Trunk
> Reporter: Pradhan Yash Sharma
> Priority: Minor
> Fix For: Trunk
>
>
> 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|https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html]
> 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);Limiting the
> scope of the method from public modifier to package level.
>
> *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|https://stackoverflow.com/questions/2078978/functional-programming-vs-object-oriented-programming],
> we can use [method
> referencing|https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html],
> 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|https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.htmlv].
>
> - 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 comparativlelly slower then ']' 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 performace to some extend
> an study can be seen on
> [this|https://stackoverflow.com/questions/24859500/concatenate-char-literal-x-vs-single-char-string-literal-x]
> page.
>
> *5.) Updated Variable Declaration*Lastly some of the variable declaration is
> 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 improvents or suggestion you
> have in mind :) # [OFBIZ-10344] Refactoring Variable Scope for
> org.apache.ofbiz.base package
> # [OFBIZ-10345] Refactoring Variable Scope for
> org.apache.ofbiz.catalina.container
> # [OFBIZ-10346] Refactoring Variable Scope for org.apache.ofbiz.common
> # [OFBIZ-10347] Refactoring Variable Scope for org.apache.ofbiz.datafile
> # [OFBIZ-10348] Refactoring Variable Scope for org.apache.ofbiz.entity
> P.S. Apart from this I am also working on performance matrix and will share
> it soon.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)