-
Notifications
You must be signed in to change notification settings - Fork 4
Don't re-calculate independent parameters #3
Description
Currently an argument iterator is re-calculated when a previous parameter is iterated:
parameterize {
val parameter1 by parameter {
println("Calculated parameter1")
listOf('a', 'b')
}
val parameter2 by parameter {
println("Calculated parameter2")
listOf(1, 2)
}
println("$parameter1$parameter2")
}Will print:
Calculated parameter1
Calculated parameter2
a1
a2
Calculated parameter2
b1
b2
Here parameter2 is being calculated more than once, which may not be a lot here, but calculating once for every combination parameters before it could easily become tens of thousands of recalculations when only one is necessary.
It behaves this way because parameterize cautiously assumes that iterating a parameter (parameter1) will require future parameters iterators to be re-calculated (e.g. if parameter2 used parameter1)
It's possible to track when parameters are declared and used, so it should be possible to see that parameter2 is declared without parameter1 being used, so parameter2 does not need to be re-calculated after iterating parameter1's argument to 'b'.