Performance tips! Boxing and unboxing cost might be high especially when in a loop (can create many heap allocations). Tail recursion If you find yourself in a situation where you are doing a recursive call (where you should first find for already existing library function to do the operation for you instead of recursive call), then do whatever possible for the recursive call to be tail recursive . A function is tail recursive if the recursive call is the last instruction performed which means only first call is in stack . A hint for many tail recursive call is that you pass some accumulator inside the recursive call, which means you are doing the calculation in the next step in the recursion as opposed to holding the accumulator outside the tail recursive call. def tailrecSum ( l : List [ Int ]) : Int = { def loop ( list : List [ Int ], acc : Int ) : Int = list match { case Nil => acc case x :: xs => loop ( xs , acc + x ) /
Software Engineering Best Practices, System Design, High Scale, Algorithms, Math, Programming Languages, Statistics, Machine Learning, Databases, Front Ends, Frameworks, Low Level Machine Structure, Papers and Computing, Computer Science Book Reviews - Everything!