Skip to content

Commit

Permalink
Revert "Retroactive attempt to establish a baseline including the new…
Browse files Browse the repository at this point in the history
… benchmarks"

This reverts commit b08196e. We've got
our baseline benchmarks now
  • Loading branch information
TimWSpence committed Mar 4, 2024
1 parent b08196e commit 92c91e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ sealed abstract private[data] class ChainInstances extends ChainInstances1 {
if (fa.isEmpty) G.pure(Chain.nil)
else
G match {
case x: StackSafeMonad[G] =>
x.map(Traverse.traverseDirectly(fa.iterator)(f)(x))(fromIterableOnce(_))
case _ =>
traverseViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand All @@ -1252,6 +1254,7 @@ sealed abstract private[data] class ChainInstances extends ChainInstances1 {

override def traverse_[G[_], A, B](fa: Chain[A])(f: A => G[B])(implicit G: Applicative[G]): G[Unit] =
G match {
case x: StackSafeMonad[G] => Traverse.traverse_Directly(fa.iterator)(f)(x)
case _ =>
foldRight(fa, Always(G.pure(()))) { (a, acc) =>
G.map2Eval(f(a), acc) { (_, _) =>
Expand Down Expand Up @@ -1368,6 +1371,8 @@ sealed abstract private[data] class ChainInstances extends ChainInstances1 {
if (fa.isEmpty) G.pure(Chain.nil)
else
G match {
case x: StackSafeMonad[G] =>
x.map(TraverseFilter.traverseFilterDirectly(fa.iterator)(f)(x))(traverse.fromIterableOnce(_))
case _ =>
traverseFilterViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/scala/cats/instances/list.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cats
package instances

import cats.data.{Chain, Ior, ZipList}
import cats.StackSafeMonad
import cats.instances.StaticMethods.appendAll
import cats.kernel.compat.scalaVersionSpecific._
import cats.kernel.instances.StaticMethods.wrapMutableIndexedSeq
Expand Down Expand Up @@ -121,6 +122,7 @@ trait ListInstances extends cats.kernel.instances.ListInstances {
if (fa.isEmpty) G.pure(Nil)
else
G match {
case x: StackSafeMonad[G] => x.map(Traverse.traverseDirectly[G, A, B](fa)(f)(x))(_.toList)
case _ =>
G.map(Chain.traverseViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand All @@ -134,7 +136,8 @@ trait ListInstances extends cats.kernel.instances.ListInstances {
*/
override def traverse_[G[_], A, B](fa: List[A])(f: A => G[B])(implicit G: Applicative[G]): G[Unit] = {
G match {
case _ =>
case x: StackSafeMonad[G] => Traverse.traverse_Directly(fa)(f)(x)
case _ =>
// the cost of this is O(size log size)
// c(n) = n + 2 * c(n/2) = n + 2(n/2 log (n/2)) = n + n (logn - 1) = n log n
// invariant: size >= 1
Expand Down Expand Up @@ -317,6 +320,7 @@ private[instances] trait ListInstancesBinCompat0 {
if (fa.isEmpty) G.pure(Nil)
else
G match {
case x: StackSafeMonad[G] => x.map(TraverseFilter.traverseFilterDirectly(fa)(f)(x))(_.toList)
case _ =>
G.map(Chain.traverseFilterViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/scala/cats/instances/vector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ trait VectorInstances extends cats.kernel.instances.VectorInstances {

final override def traverse[G[_], A, B](fa: Vector[A])(f: A => G[B])(implicit G: Applicative[G]): G[Vector[B]] =
G match {
case _ => G.map(Chain.traverseViaChain(fa)(f))(_.toVector)
case x: StackSafeMonad[G] => x.map(Traverse.traverseDirectly(fa)(f)(x))(_.toVector)
case _ => G.map(Chain.traverseViaChain(fa)(f))(_.toVector)
}

final override def updated_[A, B >: A](fa: Vector[A], idx: Long, b: B): Option[Vector[B]] =
Expand All @@ -141,7 +142,8 @@ trait VectorInstances extends cats.kernel.instances.VectorInstances {
*/
override def traverse_[G[_], A, B](fa: Vector[A])(f: A => G[B])(implicit G: Applicative[G]): G[Unit] = {
G match {
case _ =>
case x: StackSafeMonad[G] => Traverse.traverse_Directly(fa)(f)(x)
case _ =>
// the cost of this is O(size)
// c(n) = 1 + 2 * c(n/2)
// invariant: size >= 1
Expand Down Expand Up @@ -269,6 +271,7 @@ private[instances] trait VectorInstancesBinCompat0 {

def traverseFilter[G[_], A, B](fa: Vector[A])(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[Vector[B]] =
G match {
case x: StackSafeMonad[G] => TraverseFilter.traverseFilterDirectly(fa)(f)(x)
case _ =>
G.map(Chain.traverseFilterViaChain(fa)(f))(_.toVector)
}
Expand Down

0 comments on commit 92c91e4

Please sign in to comment.