You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace for with cfor in the Scala code for improved performance #439
Numerical for loops in Scala are known to be slower than their counterparts in other languages, and also generate more garbage, because they are implemented as a composition of very high-level language constructs; details can be found here and here, for instance. This is why the Spires library provides the cfor macro, which implements loops in a significantly more efficient way.
With the above rationale, would the maintainers of this repository agree to the replacing of for with cfor, for improved performance of the benchmarked Scala code?
We not like such optimizations. We try to use standard language constructs and containers. If for in Scala is slow, is not Scala developers should care about it?
Performance-sensitive code usually switches to either while-loops or tail recursive functions.
To ensure the optimization of tail recursive functions Scala standard library contains @tailrec annotation.
Scala developers usually don't care about for-loops being slow because they are used mostly for monadic binding (i.e. Scala for-comprehensions are analogues of Haskell do-comprehensions and not just loops).
Activity
kostya commentedon Dec 11, 2022
We not like such optimizations. We try to use standard language constructs and containers. If
forin Scala is slow, is not Scala developers should care about it?CoolDalek commentedon Apr 4, 2023
Performance-sensitive code usually switches to either while-loops or tail recursive functions.
To ensure the optimization of tail recursive functions Scala standard library contains
@tailrecannotation.Scala developers usually don't care about for-loops being slow because they are used mostly for monadic binding (i.e. Scala for-comprehensions are analogues of Haskell do-comprehensions and not just loops).