Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-10343

Refactoring Variable Scope

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 22.01.01, Upcoming Branch
    • None
    • framework
    • 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

        Activity

          People

            Unassigned Unassigned
            PradhanYashSharma Pradhan Yash Sharma
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: