scala performance problem