Slow Scala assert

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-03-11T13:10:43Z Indexed on 2010/03/12 16:57 UTC
Read the original article Hit count: 496

Filed under:
|
|
|

We've been profiling our code recently and we've come across a few annoying hotspots. They're in the form

assert(a == b, a + " is not equal to " + b)

Because some of these asserts can be in code called a huge amount of times the string concat starts to add up. assert is defined as:

def assert(assumption : Boolean, message : Any) = ....

why isn't it defined as:

def assert(assumption : Boolean, message : => Any) = ....

That way it would evaluate lazily. Given that it's not defined that way is there an inline way of calling assert with a message param that is evaluated lazily?

Thanks

© Stack Overflow or respective owner

Related posts about scala

Related posts about assert