stevedlawrence commented on a change in pull request #316: Assortment of 
changes to improve performance
URL: https://github.com/apache/incubator-daffodil/pull/316#discussion_r370633191
 
 

 ##########
 File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/Evaluatable.scala
 ##########
 @@ -285,7 +285,17 @@ abstract class Evaluatable[+T <: AnyRef](protected val 
ci: DPathCompileInfo, qNa
   /**
    * Preferred for use in the runtime.
    */
-  @inline final def maybeConstant = constValue_.asInstanceOf[Maybe[T]]
+  @inline final def maybeConstant = {
+    // We could just do constValue_.asInstanceOf[Maybe[T]], but the compiled
+    // bytecode ends up allocating a Maybe. Since constant values are accessed
+    // very often, we really want to avoid that overhead. The following gets
+    // rid of those unnecessary allocations.
+    if (constValue_.isDefined) {
+      Maybe[T](constValue_.get.asInstanceOf[T])
 
 Review comment:
   Will do. For reference, this was the command:
   ```bash
   find daffodil.git -name '*.class' -exec javap -p -c '{}' \; > 
dissasembled.txt
   ```
   From there, it's just a matter of grep, e.g.
   ```bash
   grep -a new disassembled.txt | grep Maybe
   ```
   Note that the -a flag is needed since there's UTF-8 characters or something 
that makes grep think the file is binary. Javap is really useful in figuring 
out why there are allocations since Scala does so much stuff behind your back.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to