Skip to content

Commit

Permalink
Runtime optimisation; minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gvonness committed Feb 16, 2022
1 parent d6b21e2 commit b2a6c37
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-XX:+UseG1GC
-XX:+UseStringDeduplication
-Xmx8G
14 changes: 14 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
rules = [
OrganizeImports
]

OrganizeImports {
coalesceToWildcardImportThreshold = 2147483647 # Int.MaxValue
expandRelative = false
groupExplicitlyImportedImplicitsSeparately = false
groupedImports = Merge
groups = ["re:javax?\\.", "scala.", "*"]
importSelectorsOrder = Ascii
importsOrder = Ascii
removeUnused = true
}
4 changes: 1 addition & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ThisBuild / baseVersion := "0.1.3"
ThisBuild / baseVersion := "0.1.4"
ThisBuild / organization := "ai.entrolution"
ThisBuild / organizationName := "Entrolution"
ThisBuild / publishGithubUser := "gvonness"
Expand All @@ -21,8 +21,6 @@ ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local"

name := "bengal-stm"

version := "0.1.3"

scalaVersion := "2.13.8"
crossScalaVersions := Seq("2.12.15", "2.13.8")

Expand Down
49 changes: 23 additions & 26 deletions src/main/scala/bengal/stm/TxnRuntimeContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@ private[stm] trait TxnRuntimeContext[F[_]] {
txnId: TxnId
)(implicit F: Concurrent[F]): F[Unit] =
for {
_ <- waitingSemaphore.acquire
_ <- withRunningLock(F.pure(runningMap -= txnId))
waitingPopulated <- F.pure(waitingBuffer.nonEmpty)
_ <- if (waitingPopulated)
triggerReprocessing
else {
F.unit
}
_ <- waitingSemaphore.acquire
_ <- withRunningLock(F.pure(runningMap -= txnId))
_ <- if (waitingBuffer.nonEmpty) triggerReprocessing else F.unit
_ <- waitingSemaphore.release
} yield ()

Expand All @@ -91,8 +86,8 @@ private[stm] trait TxnRuntimeContext[F[_]] {
for {
_ <- waitingSemaphore.acquire
_ <- F.pure(waitingBuffer.append(analysedTxn))
_ <- triggerReprocessing
_ <- waitingSemaphore.release
_ <- triggerReprocessing
} yield ()

private def attemptExecution(
Expand All @@ -118,9 +113,7 @@ private[stm] trait TxnRuntimeContext[F[_]] {
_ <- runningSemaphore.release
} yield innerResult
} else {
for {
_ <- runningSemaphore.release
} yield IdClosure.empty
runningSemaphore.release.map(_ => IdClosure.empty)
}
} yield result

Expand All @@ -133,20 +126,24 @@ private[stm] trait TxnRuntimeContext[F[_]] {
_ <- schedulerTrigger.get.flatMap(_.get)
_ <- waitingSemaphore.acquire
_ <- schedulerTrigger.set(newTrigger)
_ <- for {
bufferLocked <- F.pure(waitingBuffer.toList)
_ <- F.pure(waitingBuffer.clear())
runningClosure <- getRunningClosure
_ <- bufferLocked.foldLeftM(runningClosure) { (i, j) =>
for {
_ <- if (j.idClosure.isCompatibleWith(i)) {
attemptExecution(j)
} else {
F.pure(waitingBuffer.append(j))
}
} yield i.mergeWith(j.idClosure)
}
} yield ()
_ <- if (waitingBuffer.nonEmpty) {
for {
bufferLocked <- F.pure(waitingBuffer.toList)
_ <- F.pure(waitingBuffer.clear())
runningClosure <- getRunningClosure
_ <- bufferLocked.foldLeftM(runningClosure) { (i, j) =>
for {
_ <- if (j.idClosure.isCompatibleWith(i)) {
attemptExecution(j)
} else {
F.pure(waitingBuffer.append(j))
}
} yield i.mergeWith(j.idClosure)
}
} yield ()
} else {
F.pure(println("waiting buffer is empty"))
}
_ <- waitingSemaphore.release
} yield ()

Expand Down

0 comments on commit b2a6c37

Please sign in to comment.