Skip to content

Commit b7c5ac4

Browse files
authored
[kernel][core] IO and Async optimizations (#973)
I noticed a few regressions with recent changes while inspecting benchmarks
1 parent ce5c03a commit b7c5ac4

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

kyo-core/shared/src/main/scala/kyo/IO.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object IO:
4242
* The suspended computation wrapped in an IO effect.
4343
*/
4444
inline def apply[A, S](inline f: Safepoint ?=> A < S)(using inline frame: Frame): A < (IO & S) =
45-
Effect.defer(f)
45+
Effect.deferInline(f)
4646

4747
/** Ensures that a finalizer is run after the main computation, regardless of success or failure.
4848
*
@@ -69,7 +69,7 @@ object IO:
6969
object Unsafe:
7070

7171
inline def apply[A, S](inline f: AllowUnsafe ?=> A < S)(using inline frame: Frame): A < (IO & S) =
72-
Effect.defer {
72+
Effect.deferInline {
7373
import AllowUnsafe.embrace.danger
7474
f
7575
}

kyo-core/shared/src/main/scala/kyo/scheduler/IOPromise.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private[kyo] class IOPromise[+E, +A](init: State[E, A]) extends Safepoint.Interc
130130
case l: Linked[E, A] @unchecked =>
131131
onCompleteLoop(l.p)
132132
case v =>
133-
IOPromise.eval(f, v.asInstanceOf[Result[E, A]])
133+
IOPromise.eval(f(v.asInstanceOf[Result[E, A]]))
134134
onCompleteLoop(this)
135135
end onComplete
136136

@@ -245,10 +245,10 @@ private[kyo] object IOPromise:
245245
new Pending[E, A]:
246246
def waiters: Int = self.waiters + 1
247247
def interrupt[E2 >: E](error: Error[E2]) =
248-
eval(f, error.asInstanceOf[Error[E]])
248+
eval(f(error.asInstanceOf[Error[E]]))
249249
self
250250
def run[E2 >: E, A2 >: A](v: Result[E2, A2]) =
251-
eval(f, v.asInstanceOf[Result[E, A]])
251+
eval(f(v.asInstanceOf[Result[E, A]]))
252252
self
253253
end run
254254

@@ -265,7 +265,7 @@ private[kyo] object IOPromise:
265265
inline def onInterrupt(inline f: Error[E] => Unit): Pending[E, A] =
266266
new Pending[E, A]:
267267
def interrupt[E2 >: E](error: Error[E2]) =
268-
eval(f, error.asInstanceOf[Error[E]])
268+
eval(f(error.asInstanceOf[Error[E]]))
269269
self
270270
def waiters: Int = self.waiters + 1
271271
def run[E2 >: E, A2 >: A](v: Result[E2, A2]) =
@@ -319,8 +319,8 @@ private[kyo] object IOPromise:
319319
end Empty
320320
end Pending
321321

322-
private inline def eval[A, B](inline f: A => Unit, value: A): Unit =
323-
try f(value)
322+
private inline def eval[A](inline f: => Unit): Unit =
323+
try f
324324
catch
325325
case ex if NonFatal(ex) =>
326326
given Frame = Frame.internal

kyo-core/shared/src/main/scala/kyo/scheduler/IOTask.scala

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ sealed private[kyo] class IOTask[Ctx, E, A] private (
3434

3535
private inline def erasedAbortTag = Tag[Abort[Any]].asInstanceOf[Tag[Abort[E]]]
3636

37+
private inline def locally[A](inline f: A): A = f
38+
3739
final private def eval(startMillis: Long, clock: InternalClock)(using Safepoint) =
3840
try
3941
curr = Boundary.restoring(trace, this) {

kyo-kernel/shared/src/main/scala/kyo/kernel/Effect.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ object Effect:
6161
end try
6262
end catching
6363

64-
private[kyo] def defer[A, S](f: Safepoint ?=> A < S)(using _frame: Frame): A < S =
64+
private[kyo] def defer[A, S](f: Safepoint ?=> A < S)(using Frame): A < S =
65+
deferInline(f)
66+
67+
@nowarn("msg=anonymous")
68+
private[kyo] inline def deferInline[A, S](inline f: Safepoint ?=> A < S)(using inline _frame: Frame): A < S =
6569
new KyoDefer[A, S]:
6670
def frame = _frame
6771
def apply(v: Unit, context: Context)(using Safepoint) =

0 commit comments

Comments
 (0)