mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
DAML Engine: Use while loop instead of for loops (#7126)
This PR replaces a few `for (... to/until ...)` loops with `while` loops which explicitly maintain their counter. In my benchmarks, this has lead to a 3% performance improvement. Since the affected functions are the ones used for applying arguments to functions, similar improvements should be observable regardless of the specific benchmark. CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
51e7c88bf5
commit
37d74287f1
@ -149,10 +149,12 @@ object SExpr {
|
||||
def execute(machine: Machine): Unit = {
|
||||
val arity = builtin.arity
|
||||
val actuals = new util.ArrayList[SValue](arity)
|
||||
for (i <- 0 to arity - 1) {
|
||||
var i = 0
|
||||
while (i < arity) {
|
||||
val arg = args(i)
|
||||
val v = arg.lookupValue(machine)
|
||||
actuals.add(v)
|
||||
i += 1
|
||||
}
|
||||
builtin.execute(actuals, machine)
|
||||
}
|
||||
@ -282,10 +284,12 @@ object SExpr {
|
||||
def execute(machine: Machine): Unit = {
|
||||
val arity = builtin.arity
|
||||
val actuals = new util.ArrayList[SValue](arity)
|
||||
for (i <- 0 to arity - 1) {
|
||||
var i = 0
|
||||
while (i < arity) {
|
||||
val arg = args(i)
|
||||
val v = arg.lookupValue(machine)
|
||||
actuals.add(v)
|
||||
i += 1
|
||||
}
|
||||
val v = builtin.executePure(actuals)
|
||||
machine.env.add(v)
|
||||
@ -320,10 +324,12 @@ object SExpr {
|
||||
machine.env.size + bounds.size - 1))
|
||||
|
||||
// Start evaluating the let binders
|
||||
for (i <- 1 until bounds.size) {
|
||||
var i = 1
|
||||
while (i < bounds.size) {
|
||||
val b = bounds(bounds.size - i)
|
||||
val expectedEnvSize = machine.env.size + bounds.size - i - 1
|
||||
machine.pushKont(KPushTo(machine.env, b, machine.frame, machine.actuals, expectedEnvSize))
|
||||
i += 1
|
||||
}
|
||||
machine.ctrl = bounds.head
|
||||
}
|
||||
|
@ -406,10 +406,12 @@ private[lf] object Speedy {
|
||||
val othersLength = newArgs.length - missing
|
||||
|
||||
// Evaluate the arguments
|
||||
for (i <- 0 to newArgsLimit - 1) {
|
||||
var i = 0
|
||||
while (i < newArgsLimit) {
|
||||
val newArg = newArgs(i)
|
||||
val v = newArg.lookupValue(this)
|
||||
actuals.add(v)
|
||||
i += 1
|
||||
}
|
||||
|
||||
// Not enough arguments. Return a PAP.
|
||||
|
Loading…
Reference in New Issue
Block a user