bug icon indicating copy to clipboard operation
bug copied to clipboard

2.13 IndexedSeqOps does not override foreach in IterableOps

Open som-snytt opened this issue 4 years ago • 4 comments

reproduction steps

Issue raised at https://discord.com/channels/632150470000902164/632628489719382036/916066258649243659

LinearSeqOps got some help https://github.com/scala/scala/commit/cc53ceeb6f17fd9606e09d04b0d4b41a36348e90

problem

This is a performance regression with respect to 2.12.

@scala/collections

som-snytt avatar Dec 03 '21 02:12 som-snytt

This might be a no-brainer, but other optimizations are not.

For example, List, where it is about dispatch and not algorithmic:

  // Overridden with an implementation identical to the inherited one (at this time)
  // solely so it can be finalized and thus inlinable.
  @inline final override def foreach[U](f: A => U): Unit = {

A tool could help identify methods which are jit- and -opt-friendly, and also which deserve performance testing.

som-snytt avatar Dec 03 '21 04:12 som-snytt

Thank you for reporting! I am also surprised.

I think it should be possible to add an override in scala.collection.IndexedSeqOps. Ideally, the PR should come with benchmarks results.

julienrf avatar Dec 03 '21 07:12 julienrf

Issue raised at discord.com/channels/632150470000902164/632628489719382036/916066258649243659

for easy reference, what @WojciechMazur wrote was:

Hey, is here someone with broad knowledge about Scala 2 stdlib (collections)? I've seen a large performance regression in Scala Native between Scala 2.12- and Scala 2.13 collections. In one of my benchmarks, with large number of for-loops, I've seen that replacing seq.foreach with while-loop allows me to drop execution time by half (on the JVM by 20%). Is there some reason why IndexedSeqOps does not override foreach method to use while-loop, but uses default implementation from IterableOps with iterator instead?

SethTisue avatar Dec 13 '21 21:12 SethTisue

unassigning myself until it can be shown that there is a concrete and fixable performance problem

NthPortal avatar Jan 30 '22 21:01 NthPortal