jtulach commented on code in PR #9834:
URL: https://github.com/apache/netbeans/pull/9834#discussion_r4735476465


##########
ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootKeys.java:
##########
@@ -111,15 +124,21 @@ Collection<PrjInfo> getKeys() {
             var nestedSize = nested.size();
             nestedArr[0] = nestedSize;
 
-            var p = new ProjectsRootKeys.PrjInfo(prj, type, nestedArr);
-            nested.add(prj.getProjectDirectory());
-            dirs.add(p);
-            snapshot.put(prj, p);
+            PrjInfo parent = nested.isEmpty() ? null : nested.peekLast();
+            PrjInfo info = new ProjectsRootKeys.PrjInfo(prj, type, nestedArr);
+            nested.add(info);
+            var children = parentship.get(parent);
+            if (children == null) {
+                children = new TreeSet<>(byProjectDisplayName);
+                parentship.put(parent, children);
+            }
+            children.add(info);

Review Comment:
    > > if @mbien requires use of computeIfAbsent, I'll do it. Otherwise I 
stick with old good if
   > 
   > obviously I don't require that. its just more concise and more performant.
   
   - my reply is built on 10+ years of working on JVM compilers
   - the `computeIfAbsent` method accepts a lambda
      - lambda is handled via `LambdaMetaFactory` and involves ...
      - ... **bytecode generation** during first execution
      - that's a lot of work
      - btw. it is well known that JDK8 was 30% slower on startup than JDK7 
        - that was due to this bytecode generation ...
        - ... that regression couldn't be fixed and at the end ...
        - ... the startup regression had to be mitigated by other speedups
   - as far as _peak performance_ (the top most speed after all JIT 
compilations are done)...
      - then it is very likely the `computeIfAbsent` will **be on par** with my 
plain `if` code
      - current JIT compilers are pretty good at inlining and can "crack the 
lambda"
      - however inspecting the [compiler 
graph](https://www.graalvm.org/latest/tools/igv/) will show a huge difference:
         - while `if` version is a small graph with nodes representing 1:1 the 
Java code
         - the `computeIfAbsent` graph is going to be much bigger than its Java 
code would indicate
           - as it has to inline all the libraries up to the lambda callback
         - hence the time spend in the JIT compiler will be different and 
certainly not in favor of `computeIfAbsent` approach
         - e.g. the time to get to the peak performance is longer in 
`computeIfAbsent` case
   - moreover the _run in interpreter_ (needed before the JIT compilation is 
over) is fully depending on the amount of code
       - here the plain `if` variant clearly outperforms the ...
       - lambda approach (with the behind the scene generated byte code lambda 
class)
   - `computeIfAbstract` is slower to get to top speed and even then it is on 
par with plain `if` solution!
   
   > ...more performant...
   
   So, @mbien, there is no performance aspect I can think of where the 
`computeIfAbsent` variant would be more performant. If we want to be sure, we 
can perform some (JMH) benchmarking, but I bet _tuple of beer_, that my claims 
are accurate.
   



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to