"ExceptionBlob"

62 views
Skip to first unread message

Russ P.

unread,
Feb 2, 2016, 4:44:02 PM2/2/16
to scala-user
I just ran with Java -Xprof profiling enabled, and here is a small sample of what I get:

     Compiled + native   Method                        
 82.7%    86  +     0    ExceptionBlob
  2.9%     3  +     0    scala.collection.mutable.WrappedArray.reduceLeft
  1.9%     2  +     0    scala.collection.mutable.ArrayBuffer.foreach

What is "ExceptionBlob," and what I should look for in my code to stop it from gobbling up so much time? I don't use exceptions much. Thanks.

Naftoli Gugenheim

unread,
Feb 2, 2016, 5:00:15 PM2/2/16
to Russ P., scala-user

What is your code?


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Russ P.

unread,
Feb 2, 2016, 5:31:02 PM2/2/16
to scala-user, russ.p...@gmail.com
On Tuesday, February 2, 2016 at 2:00:15 PM UTC-8, nafg wrote:

What is your code?


It's an application of many thousands of lines of code. I'm just looking for some general guidance on this "ExceptionBlob" thing. I generally try to steer clear of "blobs" of any sort if possible.

Jason Zaugg

unread,
Feb 2, 2016, 5:43:20 PM2/2/16
to Russ P., scala-user

That might be an indication that the runtime of your benchmark is dominated by the overhead of throwing/catching exceptions.

See http://erikengbrecht.blogspot.com.au/2009/02/scala-actors-versus-exceptionblob.html and http://erikengbrecht.blogspot.com.au/2009/02/profiling-exceptionblob.html for a discussion on how using exceptions for "regular" control flow can hurt performance. There are some cases where the JVM has gotten quite good at optimizing this away: https://blogs.oracle.com/jrose/entry/longjumps_considered_inexpensive, though.

-jason

Russ P.

unread,
Feb 2, 2016, 5:57:49 PM2/2/16
to scala-user, russ.p...@gmail.com


On Tuesday, February 2, 2016 at 2:43:20 PM UTC-8, Jason Zaugg wrote:
On Wed, Feb 3, 2016 at 7:44 AM Russ P. <russ.p...@gmail.com> wrote:
I just ran with Java -Xprof profiling enabled, and here is a small sample of what I get:

     Compiled + native   Method                        
 82.7%    86  +     0    ExceptionBlob
  2.9%     3  +     0    scala.collection.mutable.WrappedArray.reduceLeft
  1.9%     2  +     0    scala.collection.mutable.ArrayBuffer.foreach

What is "ExceptionBlob," and what I should look for in my code to stop it from gobbling up so much time? I don't use exceptions much. Thanks.

That might be an indication that the runtime of your benchmark is dominated by the overhead of throwing/catching exceptions.

That is why I am baffled. The words "catch,", "throw," and "Exception" barely appear in my code (and not in any critical area).

Could this possibly have something to do with early return statements? I recall hearing some warnings about them several years ago, and I do use them.

Naftoli Gugenheim

unread,
Feb 2, 2016, 6:31:38 PM2/2/16
to Russ P., scala-user
Return inside a function (not a method) works by throwing an exception.

--

Jason Zaugg

unread,
Feb 2, 2016, 6:38:17 PM2/2/16
to Naftoli Gugenheim, Russ P., scala-user
def foo: Int = {
  if (condition) return 1 // early return is still efficient, although many people claim they hamper code readability
  val function = () => return 2 // non-local return. this is compiled into `throw new NonLocalReturnException(2) ...
  function()
  34
  // ... and an exception handler is added here to catch that exception and return the value from this method
}

-jason

Russ P.

unread,
Feb 2, 2016, 9:03:47 PM2/2/16
to scala-user, nafto...@gmail.com, russ.p...@gmail.com
I'm glad to hear that early returns are efficient, but that still leaves me wondering why my code is spending 80% of its time in the "ExceptionBlob." I don't do any non-local returns. The Java -Xprof option doesn't seem to tell me where the exceptions are that are eating up so much time. Am I missing something?

Juha Heljoranta

unread,
Feb 3, 2016, 9:54:16 AM2/3/16
to scala...@googlegroups.com, Russ P.
Perhaps using more advanced profiling tools such as Mission Control
(http://www.oracle.com/technetwork/java/javaseproducts/mission-control/index.html) or VisualVM (http://visualvm.java.net/) would help?

Cheers,
Juha
Reply all
Reply to author
Forward
0 new messages