You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2019/05/28 14:45:42 UTC

[GitHub] [skywalking] TheRealHaui commented on a change in pull request #2776: Added minor performance improvements

TheRealHaui commented on a change in pull request #2776: Added minor performance improvements
URL: https://github.com/apache/skywalking/pull/2776#discussion_r288143616
 
 

 ##########
 File path: oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/CollectionUtils.java
 ##########
 @@ -26,15 +26,15 @@
 public class CollectionUtils {
 
     public static boolean isEmpty(Map map) {
-        return map == null || map.size() == 0;
+        return map == null || map.isEmpty();
 
 Review comment:
   Hi, looking at the implementations of String#isEmpty() and/or different List#isEmpty() implementations we see mostly "== 0" statements which from a top level perspective I generally consider to be more performant than smaller or greater comparisons. Furthermore, using isEmpty() keeps one on the safe side independent of the JIT and from my personal point of view additionally makes more clear what the purpose of the line of code is.
   Of course we could create microbenchmark tests however I do trust others when the statements are so clear: https://stackoverflow.com/questions/1508975/why-is-list-size0-slower-than-list-isempty-in-java.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services