Hacker News new | ask | show | jobs
by Aqueous 4536 days ago
"I often have to back off of idiomatic Scala to achieve these goals (especially when it comes to GC pressure). "

Can you give an example of when you had to do this? I often wonder about the performance costs of chaining together several collection API calls.

1 comments

Options are the most obvious:

def foo(opt: Option[Bar]) = opt.map(_.toString).getOrElse("")

This non-obviously creates an extra object in the Some case. As opposed to:

if(opt.isDefined) opt.toString else ""

which creates 0. Not a huge deal in this specific case (unless this is a hot call). But this sort of thing is endemic to all of the standard libraries.

Edit -- only 1 extra object, but it is in both the Some & None case (which is sort of the point, it is hard to know with idiomatic Scala)