Skip to content

Commit

Permalink
these benchmarks …
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgk committed Mar 2, 2024
1 parent 785638e commit 3b54852
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package examples.demo.ui

import reactives.default.*
import reactives.default.{*}

import java.awt.event.*
import java.awt.{Event as _, Shape as _, *}
Expand All @@ -16,7 +16,7 @@ class ShapesPanel(val shapes: Signal[Iterable[Shape]]) extends Panel {
allChanges observe { _ => repaint() }

override def paintComponent(g: Graphics2D): Unit = {
implicitScheduler.forceNewTransaction() { implicit turn =>
scheduler.forceNewTransaction() { implicit turn =>
g.setColor(Color.WHITE)
g.fillRect(0, 0, size.width, size.height)
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger
import benchmarks.{EngineParam, Workload}
import org.openjdk.jmh.annotations.*
import reactives.core.ScopeSearch
import reactives.operator.Interface

@AuxCounters
Expand Down Expand Up @@ -59,14 +58,14 @@ class ExpensiveConflict {
@Group("g")
@GroupThreads(1)
def cheap() = {
cheapSource.set(input.incrementAndGet())(scheduler, ScopeSearch.fromSchedulerImplicit(scheduler))
cheapSource.set(input.incrementAndGet())
}

@Benchmark
@Group("g")
@GroupThreads(1)
def expensive(counter: EvaluationCounter) = {
expensiveSource.set(input.incrementAndGet())(scheduler, ScopeSearch.fromSchedulerImplicit(scheduler))
expensiveSource.set(input.incrementAndGet())
counter.tried += tried
counter.succeeded += 1
tried = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import benchmarks.philosophers.PhilosopherTable.{Philosopher, Thinking}
import benchmarks.{BusyThreads, EngineParam, Workload}
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.{BenchmarkParams, ThreadParams}
import reactives.core.ScopeSearch
import reactives.core.PlanTransactionScope
import reactives.parrp.Backoff

import scala.annotation.tailrec
Expand Down Expand Up @@ -37,10 +37,7 @@ class PhilosopherCompetition {

def tryUpdateCycle(comp: Competition)(seating: comp.stableTable.Seating): Boolean = {
val res = comp.stableTable.tryEat(seating)
if (res) seating.philosopher.set(Thinking)(
comp.stableTable.engine.scheduler,
ScopeSearch.fromSchedulerImplicit(comp.stableTable.engine.scheduler)
)
if (res) seating.philosopher.set(Thinking)(using comp.stableTable.engine.scheduler)
!res
}

Expand Down Expand Up @@ -73,8 +70,7 @@ class PhilosopherCompetition {
thirdLock.lock()
try {
seating.philosopher.set(Thinking)(
comp.stableTable.engine.scheduler,
ScopeSearch.fromSchedulerImplicit(comp.stableTable.engine.scheduler)
using comp.stableTable.engine.scheduler,
)
} finally { thirdLock.unlock() }
} finally { secondLock.unlock() }
Expand Down Expand Up @@ -132,8 +128,7 @@ class Competition extends BusyThreads {
stableTable.seatings.foreach { seat =>
val phil: stableTable.engine.Var[Philosopher] = seat.philosopher
phil.set(Thinking)(
stableTable.engine.scheduler,
ScopeSearch.fromSchedulerImplicit(stableTable.engine.scheduler)
using stableTable.engine.scheduler,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.util.concurrent.locks.{Lock, ReentrantLock}
import benchmarks.{EngineParam, Size, Step, Workload}
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.{BenchmarkParams, ThreadParams}
import reactives.core.ScopeSearch
import reactives.operator.Interface

@BenchmarkMode(Array(Mode.Throughput))
Expand Down Expand Up @@ -48,11 +47,11 @@ class MultiReverseFan {
@Benchmark
def run(step: Step, params: ThreadParams): Unit = {
val index = params.getThreadIndex
if (locks == null) sources(index).set(step.run())(scheduler, ScopeSearch.fromSchedulerImplicit(scheduler))
if (locks == null) sources(index).set(step.run())(using scheduler)
else {
locks(index / groupSize).lock()
try {
sources(index).set(step.run())(scheduler, ScopeSearch.fromSchedulerImplicit(scheduler))
sources(index).set(step.run())(using scheduler)
} finally locks(index / groupSize).unlock()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package benchmarks.simple

import benchmarks.{EngineParam, Step, Workload}
import org.openjdk.jmh.annotations.*
import reactives.core.ScopeSearch
import reactives.operator.Interface

import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -87,6 +86,6 @@ class NaturalGraph {
}

@Benchmark
def run(step: Step): Unit = source.set(step.run())(scheduler, ScopeSearch.fromSchedulerImplicit(scheduler))
def run(step: Step): Unit = source.set(step.run())(using scheduler)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package benchmarks.simple
import benchmarks.{EngineParam, Step, Workload}
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.ThreadParams
import reactives.core.ScopeSearch
import reactives.operator.Interface

import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -40,7 +39,7 @@ class ReverseFan {
@Benchmark
def run(step: Step, params: ThreadParams): Unit =
if (isManual) synchronized {
sources(params.getThreadIndex).set(step.run())(scheduler, ScopeSearch.fromSchedulerImplicit(scheduler))
sources(params.getThreadIndex).set(step.run())(using scheduler)
}
else sources(params.getThreadIndex).set(step.run())(scheduler, ScopeSearch.fromSchedulerImplicit(scheduler))
else sources(params.getThreadIndex).set(step.run())(using scheduler)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ trait PlanTransactionScope[State[_]] {

object PlanTransactionScope {

implicit def fromScheduler[State[_]](scheduler: Scheduler[State]): DynamicTransactionLookup[State] = DynamicTransactionLookup(scheduler)

case class StaticInTransaction[State[_]](tx: Transaction[State], scheduler: Scheduler[State])
extends PlanTransactionScope[State] {
override def planTransaction(inintialWrites: ReSource.of[State]*)(admissionPhase: AdmissionTicket[State] => Unit)
Expand All @@ -59,11 +61,11 @@ object PlanTransactionScope {
}
}

case class DynamicTransactionLookup[State[_]](ds: DynamicScope[State], scheduler: Scheduler[State])
case class DynamicTransactionLookup[State[_]](scheduler: Scheduler[State])
extends PlanTransactionScope[State] {
override def planTransaction(inintialWrites: ReSource.of[State]*)(admissionPhase: AdmissionTicket[State] => Unit)
: Unit =
ds.maybeTransaction match
scheduler.dynamicScope.maybeTransaction match
case Some(tx) => tx.observe { () =>
scheduler.forceNewTransaction(inintialWrites*)(admissionPhase)
}
Expand All @@ -73,6 +75,6 @@ object PlanTransactionScope {

inline given search(using ts: TransactionScope[Interface.State]): PlanTransactionScope[Interface.State] =
ts.static match
case None => DynamicTransactionLookup(Interface.default.dynamicScope, Interface.default)
case None => DynamicTransactionLookup(Interface.default)
case Some(tx) => StaticInTransaction(tx, Interface.default)
}

0 comments on commit 3b54852

Please sign in to comment.