From dev-return-110742-archive-asf-public=cust-asf.ponee.io@ofbiz.apache.org Mon Apr 30 08:22:33 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7D210180647 for ; Mon, 30 Apr 2018 08:22:32 +0200 (CEST) Received: (qmail 71843 invoked by uid 500); 30 Apr 2018 06:22:30 -0000 Mailing-List: contact dev-help@ofbiz.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ofbiz.apache.org Delivered-To: mailing list dev@ofbiz.apache.org Received: (qmail 71827 invoked by uid 99); 30 Apr 2018 06:22:29 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Apr 2018 06:22:29 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 182AFC0033 for ; Mon, 30 Apr 2018 06:22:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.979 X-Spam-Level: * X-Spam-Status: No, score=1.979 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=hotwaxsystems-com.20150623.gappssmtp.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id k835Zu20s3oo for ; Mon, 30 Apr 2018 06:22:25 +0000 (UTC) Received: from mail-oi0-f45.google.com (mail-oi0-f45.google.com [209.85.218.45]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 92A505F178 for ; Mon, 30 Apr 2018 06:22:24 +0000 (UTC) Received: by mail-oi0-f45.google.com with SMTP id 11-v6so6549375ois.8 for ; Sun, 29 Apr 2018 23:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotwaxsystems-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=6CqVZhKZkBb2nTS4wbf/+55Ym7+r5eBF8U0ITrV9icU=; b=JMFcYnGlTTJokVFua+sed2dXdlhP49mnlfPevlbJQg0ni9VqwQUBjbvtX2xTixj1yV IAhvmvUUPWpBnBNHrC34/rm9vgc2vPQZTT5CDtGTGpL6pkXzH9Z9P7ro1lrnPNGCw6P0 76y61piKLp9boMJIf7jjk+ch0+td9Si4UpxYJ5pd/ThtHb4CpEj4oBaThQnDPuEF7nsI 5Fm6KfI58vtGzOeGm4wuSiMYZe9ycuzDrLeEzmCTSOwETYNwfR6XQV0t8vP3ZDBaO2f+ 4zCL57r/FyNPlOvCl4lFzlcLOcMkoh/EDo9hjN4npZS7aa0GMZys2bAocZtjGb4CLf7/ 9K9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=6CqVZhKZkBb2nTS4wbf/+55Ym7+r5eBF8U0ITrV9icU=; b=BKRrC4+JIHcU4YKlLEKXwprYedvfYXW+XTTEjHNQo3/TVVs0W9Z9pSy1dkTEXD0qo7 dOF3EdwzSXfwMjZ3kv4dqsJKaKKFjNdM2kWXS0kjmhe6DRRFSBzYc6UnCy3cQ+5KwcNd AsQkikrHzWlzeC7bktfGj8fE2thpk8/tI6WHwKTIo/S6GG9gXh0E0ZqTqV9GjwRuq0kx 2A2QFzNDFyVB2YjRQLkOGXKcdn14E5kSzaTcW4brtQIsmcKGpQelpsPjUHfAhYogBceF cDlwVO4v1vzJJAKrODbfDsiVJCPrfVfeCQ1iQkCEcK/2QQvX50z5cqn3HFpVgQ/pFisk yxBQ== X-Gm-Message-State: ALQs6tB3zvh3O2fPoR3hDDO6wNM55NqWLY4Gtv/lpUrZHkW/6UxyCq+V DF8RRj/ufgSQssqmJi3rd7WSoqmEilOjyFF+6rs2RBUL X-Google-Smtp-Source: AB8JxZpofhNzBXe1Ou9dKHBfwVMEd9Y4heVrqY5b40CpJR7IXc4TuHFGAZAcbOGkv2jsvy7wESXLZLjIYBX86O53ERA= X-Received: by 2002:aca:37d5:: with SMTP id e204-v6mr6695428oia.21.1525069343078; Sun, 29 Apr 2018 23:22:23 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:4310:0:0:0:0:0 with HTTP; Sun, 29 Apr 2018 23:21:42 -0700 (PDT) In-Reply-To: References: From: Yash Sharma Date: Mon, 30 Apr 2018 11:51:42 +0530 Message-ID: Subject: Re: Accessibility scope of variables in Java packages and modules To: dev@ofbiz.apache.org Content-Type: multipart/alternative; boundary="00000000000073d12b056b0ae049" --00000000000073d12b056b0ae049 Content-Type: text/plain; charset="UTF-8" * I am not pen downing things, but yea I am really full on high energy to work on these front. Thanks & Regards, -- *Pradhan Yash Sharma* On Mon, Apr 30, 2018 at 11:37 AM, Yash Sharma wrote: > Hello, > > Thank you for the response, I was wondering about the volume of > refactoring we can do at each component, so let's apply Divide and Conquer > approach for each component upgrading work. > > I can see a few patterns for the update which I've listed down in my > previous mail. We can pick any piece of code and apply focused refactoring > on each component, and then we can do it with others as well when we are > through with one. It would be a great help if you could suggest a sequence > to do so for example : > *I --> 4.) Use of single quote for a character *(this is a > straightforward work and the easiest one :) ). > *II --> **3.) Using Type Inference *(We can pick this as it will never > impact any working code). > III --> *5.) Updated Variable Declaration.* > *IV --> **1.) **Downsize Accessibility Scope *(If tested this is also a > not a big deal). > *V --> **2.) Using **Lambda Expressions *(This can impact on working > hence put at last) > > This is what I can think :) Please mentor me on this and suggest any > better action plan we can opt for. > > I am very much excited to work on and implement some really cool things > that Java Ecosystem can offer us like Functional Programming, Jigsaw > , or Local Variable Type > Inference > , > I am not penning dowing > > > Thanks & Regards, > -- > *Pradhan Yash Sharma* > > On Sat, Apr 28, 2018 at 6:59 PM, Taher Alkhateeb < > slidingfilaments@gmail.com> wrote: > >> Hello Yash, >> >> Thank you for your work on this so far. It's great to see people >> focusing on refactoring, which I think should probably be the top >> priority for all of us. >> >> I will review the JIRAs some more over the coming days, but I have a >> concern that some of the patches are very large. >> >> We had many discussions in the past about focused refactoring vs. >> general trends. Focused refactoring means you go after a specific >> piece of code like a class or group of related classes / artifacts and >> fixing them. General trends, on the other hand, means that you >> identify a certain pattern and then making a sweeping change across >> the entire code base. >> >> General trends refactorings can be very dangerous, because you are >> running after a "trend" not isolating a specific piece of code and >> fixing it. >> >> So my recommendation, especially for the bigger patches that you have, >> is to redesign / refactor so that it is a topic-based, not >> trend-based. We need to make these commits in isolated bite-sized >> chunks that focus on a specific area instead of a specific trend (make >> public to private, add try-with-resources, or whatever else) >> >> Cheers, >> Taher >> >> On Thu, Apr 19, 2018 at 3:24 PM, Yash Sharma >> wrote: >> > Hi Devs, >> > >> > 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 cache, K key, V >> oldValue); >> > + void noteKeyRemoval(UtilCache 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 initParameters = new >> LinkedHashMap<>(); >> > - for (Element e : initParamList) { >> > - initParameters.put(e.getAttribute("name"), >> > e.getAttribute("value")); >> > - } >> > + Map 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 >> > > ramming-vs-object-oriented-programming>, >> > we can use method referencing >> > > eferences.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 >> > > peInference.htmlv> >> > . >> > >> > - Map systemProps = >> > UtilGenerics. checkMap(System.getProperties()); >> > + Map 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 >> > > 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 :) >> > >> > >> > 1. [OFBIZ-10344] Refactoring Variable Scope for >> > org.apache.ofbiz.base package >> > >> > 2. [OFBIZ-10345] Refactoring Variable Scope for >> > org.apache.ofbiz.catalina.container >> > >> > 3. [OFBIZ-10346] Refactoring Variable Scope for >> > org.apache.ofbiz.common >> > >> > 4. [OFBIZ-10347] Refactoring Variable Scope for >> > org.apache.ofbiz.datafile >> > >> > 5. [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. >> > >> > >> > Thanks & Regards, >> > >> > -- >> > *Pradhan Yash Sharma* >> > >> > >> > On Tue, Apr 17, 2018 at 11:28 AM, Yash Sharma < >> yash.sharma@hotwaxsystems.com >> >> wrote: >> > >> >> Thank you for the feedback I've created a Jira ticket OFBIZ-10343 >> >> and I will add >> >> patches for the same for your review. >> >> >> >> Thanks & Regards, >> >> -- >> >> *Pradhan Yash Sharma* >> >> >> >> On Fri, Apr 13, 2018 at 5:50 PM, Taher Alkhateeb < >> >> slidingfilaments@gmail.com> wrote: >> >> >> >>> Hello Pradhan, >> >>> >> >>> Refactoring is exactly what we need and is a welcomed activity. I >> >>> think we should, however, try to avoid "big ideas" across the entire >> >>> code base. The subject of your message is the reason why I say that. >> >>> >> >>> So, if you want to start refactoring, I suggest to start with one >> >>> piece of code, study it careful, issue a JIRA, and provide a patch. >> >>> This should be focused similar to your notes on UtilCache. >> >>> >> >>> On Fri, Apr 13, 2018 at 12:14 PM, Pradhan Yash Sharma >> >>> wrote: >> >>> > Hello, >> >>> > >> >>> > While I was working on UtilCache.java file came across some >> >>> improvements, >> >>> > they are as follows: >> >>> > >> >>> > 1) Method and Variable access modifiers can be narrowed down to >> private >> >>> > access modifier. >> >>> > >> >>> > 2) Then AtomicLong can be given value 0L instead of 0. >> >>> > >> >>> > 3) Some Variables is used in both synchronized and unsynchronized >> >>> blocks, >> >>> > so they can be declared final. eg, >> >>> > >> >>> > >> >>> > >> >>> > *protected AtomicLong hitCount = new AtomicLong(0); >> >>> private >> >>> > final AtomicLong hitCount = new AtomicLong(0L);* >> >>> > One variable was able to get most of my attention is >> >>> > >> >>> > * protected ConcurrentMap> >> >>> memoryTable >> >>> > = null;* >> >>> > >> >>> > This is used in synchronized and unsynchronized blocks, this Object >> can >> >>> be >> >>> > converted into ThreadLocal or AtomicReference but it would require >> >>> changes >> >>> > in the current implementation as well. >> >>> > >> >>> > Lastly, there is extensive use of for loops for iteration we can use >> >>> Java 8 >> >>> > Streams, Collector, and other functions to leverage implicit looping >> >>> > mechanism. >> >>> > >> >>> > >> >>> > -- >> >>> > Pradhan Yash Sharma >> >>> >> >> >> >> >> > > --00000000000073d12b056b0ae049--