You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2020/01/23 20:57:29 UTC

[GitHub] [incubator-daffodil] bsloane1650 commented on a change in pull request #316: Assortment of changes to improve performance

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

 ##########
 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:
   When I was working on the DataValues class, I got into a workflow, where I would look dissassembly all the *.class files and look for allocations of DataValue. I also did a similar trick when I was looking for scala.lang.BigInt/BigDecimal.
   
   It is probably more work then it is worth to do this in an automated fashion (particularly because removing all boxing would likely be a lot more effort then it is worth), however, it might be worth doing this as a one off. Possibly also document the process on the wiki and repeat it manually on occasion.
   
   

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