Skip to content

Commit

Permalink
Revert "ZIO Runtime System Improvements (2.1 candidate) (#8582)"
Browse files Browse the repository at this point in the history
This reverts commit 0304398.
  • Loading branch information
adamgfraser committed Jan 2, 2024
1 parent 7a382da commit f24db37
Show file tree
Hide file tree
Showing 32 changed files with 777 additions and 728 deletions.
2 changes: 1 addition & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Dcats.effect.stackTracingMode=full
-Dcats.effect.stackTracingMode=full
31 changes: 28 additions & 3 deletions benchmarks/src/main/scala/zio/BroadFlatMapBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import scala.concurrent.Await
@State(JScope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(16)
@Warmup(iterations = 10, time = 1)
@Measurement(iterations = 10, time = 1)
@Fork(1)
class BroadFlatMapBenchmark {
@Param(Array("20"))
Expand Down Expand Up @@ -44,6 +43,32 @@ class BroadFlatMapBenchmark {
.get()
}

@Benchmark
def monoBroadFlatMap(): BigInt = {
import reactor.core.publisher.Mono

def fib(n: Int): Mono[BigInt] =
if (n <= 1) Mono.fromSupplier(() => n)
else
fib(n - 1).flatMap(a => fib(n - 2).flatMap(b => Mono.fromSupplier(() => a + b)))

fib(depth)
.block()
}

@Benchmark
def rxSingleBroadFlatMap(): BigInt = {
import io.reactivex.Single

def fib(n: Int): Single[BigInt] =
if (n <= 1) Single.fromCallable(() => n)
else
fib(n - 1).flatMap(a => fib(n - 2).flatMap(b => Single.fromCallable(() => a + b)))

fib(depth)
.blockingGet()
}

@Benchmark
def twitterBroadFlatMap(): BigInt = {
import com.twitter.util.{Await, Future}
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/src/main/scala/zio/ForEachBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import java.util.concurrent.TimeUnit
@State(JScope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(16)
@Measurement(iterations = 5, timeUnit = TimeUnit.SECONDS, time = 3)
@Warmup(iterations = 5, timeUnit = TimeUnit.SECONDS, time = 3)
@Fork(1)
class ForEachBenchmark {

Expand Down
4 changes: 0 additions & 4 deletions benchmarks/src/main/scala/zio/ForkJoinBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import java.util.concurrent.TimeUnit
@State(JScope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(16)
@Fork(1)
class ForkJoinBenchmark {
import BenchmarkUtil.unsafeRun

Expand Down
4 changes: 0 additions & 4 deletions benchmarks/src/main/scala/zio/NarrowFlatMapBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import scala.concurrent.Await
@State(JScope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(16)
@Fork(1)
class NarrowFlatMapBenchmark {
@Param(Array("1000"))
var size: Int = _
Expand Down
4 changes: 0 additions & 4 deletions benchmarks/src/main/scala/zio/RegionBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ import java.util.concurrent.TimeUnit
@State(JScope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(16)
@Fork(1)
class RegionBenchmark {
import BenchmarkUtil.unsafeRun

Expand Down
4 changes: 0 additions & 4 deletions benchmarks/src/main/scala/zio/UnsafeRunBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ import java.util.concurrent.TimeUnit
@State(JScope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(16)
@Fork(1)
class UnsafeRunBenchmark {
import BenchmarkUtil.unsafeRun

Expand Down
46 changes: 23 additions & 23 deletions core-tests/shared/src/test/scala/zio/RuntimeBootstrapTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -620,32 +620,32 @@ object RuntimeBootstrapTests {

def main(args: Array[String]): Unit = {
val _ = ()
runtimeFlags()
helloWorld()
fib()
iteration()
asyncInterruption()
syncInterruption()
race()
autoInterruption()
autoInterruption2()
asyncInterruptionOfNever()
interruptRacedForks()
useInheritance()
useInheritance2()
asyncUninterruptible()
uninterruptibleClosingScope()
syncInterruption2()
acquireReleaseDisconnect()
disconnectedInterruption()
interruptibleAfterRace()
// runtimeFlags()
// helloWorld()
// fib()
// iteration()
// asyncInterruption()
// syncInterruption()
// race()
// autoInterruption()
// autoInterruption2()
// asyncInterruptionOfNever()
// interruptRacedForks()
// useInheritance()
// useInheritance2()
// asyncUninterruptible()
// uninterruptibleClosingScope()
// syncInterruption2()
// acquireReleaseDisconnect()
// disconnectedInterruption()
// interruptibleAfterRace()
// uninterruptibleRace()
interruptionDetection()
interruptionRecovery()
// interruptionDetection()
// interruptionRecovery()
// cooperativeYielding()
// interruptionOfForkedRace()
stackTrace1()
stackTrace2()
// stackTrace1()
// stackTrace2()
// interruptibleHole()
// queueOfferInterruption()
// localSupervision()
Expand Down
2 changes: 1 addition & 1 deletion core-tests/shared/src/test/scala/zio/SupervisorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object SupervisorSpec extends ZIOBaseSpec {
f <- ZIO.sleep(10.millis).fork.supervised(onEndSup)
_ <- (f.await).supervised(onResumeSup)
value <- onResumeSup.value
} yield assertTrue(value > 0)
} yield assertTrue(value == 1)
} @@ TestAspect.nonFlaky @@ TestAspect.withLiveClock,
suite("laws") {
DifferSpec.diffLaws(Differ.supervisor)(genSupervisor)((left, right) =>
Expand Down
12 changes: 6 additions & 6 deletions core-tests/shared/src/test/scala/zio/ZIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ object ZIOSpec extends ZIOBaseSpec {
promise1 <- Promise.make[Nothing, Unit]
promise2 <- Promise.make[Nothing, Unit]
left = promise2.await
right1 = (promise1.await *> ZIO.fail("fail")).uninterruptible
right1 = promise1.await *> ZIO.fail("fail")
right2 = (promise1.succeed(()) *> ZIO.never).ensuring(promise2.interrupt *> ZIO.never.interruptible)
exit <- ZIO.collectAllPar(List(left, ZIO.collectAllPar(List(right1, right2)))).exit
} yield assert(exit)(failsCause(containsCause(Cause.fail("fail"))))
Expand Down Expand Up @@ -2843,12 +2843,12 @@ object ZIOSpec extends ZIOBaseSpec {
.ensuring(ensuring.succeed(()) *> ZIO.interruptible(ZIO.never))
.mapError(_ => 42)
)
.catchAllCause(cause => ZIO.succeed(cause))
.catchAllCause(cause => ZIO.succeed(cause.defects))
.fork
}
cause <- ensuring.await *> fiber.interrupt.flatMap(ZIO.done(_))
} yield assertTrue(cause.defects.length == 1)
} @@ nonFlaky
failures <- ensuring.await *> fiber.interrupt.flatMap(ZIO.done(_))
} yield assertTrue(failures.length == 1)
}

} @@ zioTag(interruption),
suite("RTS concurrency correctness")(
Expand Down Expand Up @@ -4177,7 +4177,7 @@ object ZIOSpec extends ZIOBaseSpec {
right2 = (promise1.succeed(()) *> ZIO.never).ensuring(promise2.interrupt *> ZIO.never.interruptible)
exit <- left.zipPar(right1.zipPar(right2)).exit
} yield assert(exit)(failsCause(containsCause(Cause.fail("fail"))))
} @@ nonFlaky(100),
} @@ nonFlaky(1000),
test("is interruptible") {
for {
promise1 <- Promise.make[Nothing, Unit]
Expand Down
5 changes: 0 additions & 5 deletions core/js/src/main/scala/zio/internal/OneShot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ private[zio] final class OneShot[A] private (var value: A) {
if (value == null) throw new Error("Cannot block for result to be set in JavaScript")
value
}

def get(timeout: Long): A = {
val _ = timeout
get()
}
}

private[zio] object OneShot {
Expand Down
2 changes: 0 additions & 2 deletions core/js/src/main/scala/zio/internal/PlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ private[zio] trait PlatformSpecific {
*/
final def getCurrentThreadGroup()(implicit unsafe: zio.Unsafe): String = ""

final val hasGreenThreads: Boolean = false

/**
* Returns whether the current platform is ScalaJS.
*/
Expand Down
4 changes: 2 additions & 2 deletions core/jvm/src/main/scala/zio/RuntimePlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package zio

import zio.internal.{Blocking, IsFatal, LoomSupport}
import zio.internal.{Blocking, IsFatal}
import zio.stacktracer.TracingImplicits.disableAutoTrace

private[zio] trait RuntimePlatformSpecific {

final val defaultExecutor: Executor =
LoomSupport.newVirtualThreadPerTaskExecutor().map(Executor.fromJavaExecutor(_)).getOrElse(Executor.makeDefault())
Executor.makeDefault()

final val defaultBlockingExecutor: Executor =
Blocking.blockingExecutor
Expand Down
2 changes: 1 addition & 1 deletion core/jvm/src/main/scala/zio/ZIOAppPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private[zio] trait ZIOAppPlatformSpecific { self: ZIOApp =>
private def interruptRootFibers(fiberId: FiberId)(implicit trace: Trace): UIO[Unit] =
for {
roots <- Fiber.roots
_ <- Fiber.interruptAll(roots.view.filter(fiber => fiber.isAlive() && fiber.id != fiberId))
_ <- Fiber.interruptAll(roots.view.filter(fiber => fiber.isAlive()(Unsafe.unsafe) && fiber.id != fiberId))
} yield ()

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import zio.stacktracer.TracingImplicits.disableAutoTrace
import java.util.concurrent.{RejectedExecutionException, ThreadPoolExecutor}

private[zio] abstract class DefaultExecutors {

final def makeDefault(): zio.Executor =
makeDefault(true)

Expand Down
49 changes: 0 additions & 49 deletions core/jvm/src/main/scala/zio/internal/LoomSupport.scala

This file was deleted.

0 comments on commit f24db37

Please sign in to comment.