summaryrefslogtreecommitdiff
path: root/opendc-simulator
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-23 14:45:56 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-03 17:17:36 +0200
commita4a611c45dfd5f9e379434f1dc459128cb437338 (patch)
treebee4390dfcaacf71e55c9953b22bf9ef4deec38b /opendc-simulator
parent0ffd93933228e87a205c9839d1bf04cd0e178e8c (diff)
perf(simulator): Use direct field access for perf-sensitive code
This change updates the SimResourceDistributorMaxMin implementation to use direct field accesses in the perf-sensitive code.
Diffstat (limited to 'opendc-simulator')
-rw-r--r--opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt22
1 files changed, 12 insertions, 10 deletions
diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt
index 6c1e134b..63cfbdac 100644
--- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt
+++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt
@@ -162,6 +162,8 @@ public class SimResourceDistributorMaxMin(
return SimResourceCommand.Idle()
}
+ val now = interpreter.clock.millis()
+
val capacity = ctx.capacity
var duration: Double = Double.MAX_VALUE
var deadline: Long = Long.MAX_VALUE
@@ -171,7 +173,7 @@ public class SimResourceDistributorMaxMin(
// Pull in the work of the outputs
val outputIterator = activeOutputs.listIterator()
for (output in outputIterator) {
- output.pull()
+ output.pull(now)
// Remove outputs that have finished
if (!output.isActive) {
@@ -206,7 +208,7 @@ public class SimResourceDistributorMaxMin(
duration = min(duration, output.work / grantedSpeed)
}
- val targetDuration = min(duration, (deadline - interpreter.clock.millis()) / 1000.0)
+ val targetDuration = min(duration, (deadline - now) / 1000.0)
var totalRequestedWork = 0.0
var totalAllocatedWork = 0.0
for (output in activeOutputs) {
@@ -219,7 +221,7 @@ public class SimResourceDistributorMaxMin(
}
}
- assert(deadline >= interpreter.clock.millis()) { "Deadline already passed" }
+ assert(deadline >= now) { "Deadline already passed" }
this.totalRequestedSpeed = totalRequestedSpeed
this.totalAllocatedWork = totalAllocatedWork
@@ -254,27 +256,27 @@ public class SimResourceDistributorMaxMin(
/**
* The current requested work.
*/
- var work: Double = 0.0
+ @JvmField var work: Double = 0.0
/**
* The requested limit.
*/
- var limit: Double = 0.0
+ @JvmField var limit: Double = 0.0
/**
* The current deadline.
*/
- var deadline: Long = Long.MAX_VALUE
+ @JvmField var deadline: Long = Long.MAX_VALUE
/**
* The processing speed that is allowed by the model constraints.
*/
- var allowedSpeed: Double = 0.0
+ @JvmField var allowedSpeed: Double = 0.0
/**
* The actual processing speed.
*/
- var actualSpeed: Double = 0.0
+ @JvmField var actualSpeed: Double = 0.0
/**
* The timestamp at which we received the last command.
@@ -363,9 +365,9 @@ public class SimResourceDistributorMaxMin(
/**
* Pull the next command if necessary.
*/
- fun pull() {
+ fun pull(now: Long) {
val ctx = ctx
- if (ctx != null && lastCommandTimestamp < ctx.clock.millis()) {
+ if (ctx != null && lastCommandTimestamp < now) {
ctx.flush()
}
}