From 32e1a9b1d1842b659c40277394f81939fbcb5691 Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Wed, 2 Nov 2022 11:47:39 +0400 Subject: [PATCH] Fixed benchmark compilation (#3781) --- .../com/wavesplatform/RollbackBenchmark.scala | 12 ++-- .../v1/AddressFromPublicKeyBenchmark.scala | 2 +- .../lang/v1/BigIntToStringBenchmark.scala | 2 +- .../v1/EnvironmentFunctionsBenchmark.scala | 16 ++--- .../lang/v1/EvaluatorV2Benchmark.scala | 11 ++-- .../wavesplatform/lang/v1/FoldBenchmark.scala | 2 +- .../lang/v1/FractionBigIntBenchmark.scala | 6 +- .../lang/v1/FractionIntBenchmark.scala | 31 +++++----- .../lang/v1/ListIndexOfBenchmark.scala | 6 +- .../lang/v1/PowBigIntBenchmark.scala | 2 +- .../lang/v1/PowIntBenchmark.scala | 4 +- .../lang/v1/PureFunctionsRebenchmark.scala | 6 +- .../lang/v1/ScriptEvaluatorBenchmark.scala | 38 ++++++------ .../lang/v1/SqrtCbrtBigIntBenchmark.scala | 2 +- .../lang/v1/SqrtIntBenchmark.scala | 4 +- .../com/wavesplatform/lang/v1/package.scala | 3 +- .../protobuf/SmartNoSmartBenchmark.scala | 58 ++++++++++++++++--- build.sbt | 2 +- 18 files changed, 125 insertions(+), 82 deletions(-) diff --git a/benchmark/src/test/scala/com/wavesplatform/RollbackBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/RollbackBenchmark.scala index 5a957e59c91..dd79c49b02a 100644 --- a/benchmark/src/test/scala/com/wavesplatform/RollbackBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/RollbackBenchmark.scala @@ -7,11 +7,11 @@ import com.google.protobuf.ByteString import com.wavesplatform.account.{Address, AddressScheme, KeyPair} import com.wavesplatform.block.Block import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils._ -import com.wavesplatform.database.{openDB, LevelDBWriter} +import com.wavesplatform.common.utils.* +import com.wavesplatform.database.{LevelDBWriter, openDB} import com.wavesplatform.protobuf.transaction.PBRecipients import com.wavesplatform.state.{Diff, Portfolio} -import com.wavesplatform.transaction.{GenesisTransaction, Proofs} +import com.wavesplatform.transaction.{GenesisTransaction, Proofs, TxDecimals, TxPositiveAmount} import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.utils.{NTP, ScorexLogging} @@ -40,11 +40,11 @@ object RollbackBenchmark extends ScorexLogging { issuer.publicKey, ByteString.copyFromUtf8("asset-" + i), ByteString.EMPTY, - 100000e2.toLong, - 2.toByte, + TxPositiveAmount.unsafeFrom(100000e2.toLong), + TxDecimals.unsafeFrom(2.toByte), false, None, - 1e8.toLong, + TxPositiveAmount.unsafeFrom(1e8.toLong), time.getTimestamp(), Proofs(ByteStr(new Array[Byte](64))), AddressScheme.current.chainId diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala index 2b67cc8d769..4d1259a5397 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala @@ -29,7 +29,7 @@ class AddressFromPublicKeyBenchmark { @State(Scope.Benchmark) class PkSt extends EthHelpers { val ds = DirectiveSet(V6, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(EnvironmentFunctionsBenchmark.environment) + val ctx = lazyContexts((ds, true)).value().evaluationContext(EnvironmentFunctionsBenchmark.environment) val wavesPk = ByteStr(curve25519.generateKeypair._2) val exprWaves = TestCompiler(V6).compileExpression(s"addressFromPublicKey(base58'$wavesPk')").expr.asInstanceOf[EXPR] diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/BigIntToStringBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/BigIntToStringBenchmark.scala index 5315fbf5744..16b8652c738 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/BigIntToStringBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/BigIntToStringBenchmark.scala @@ -27,7 +27,7 @@ class BigIntToStringBenchmark { @State(Scope.Benchmark) class BigIntToStringSt { val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) + val ctx = lazyContexts((ds, true)).value().evaluationContext(Common.emptyBlockchainEnvironment()) val expr = FUNCTION_CALL( Native(BIGINT_TO_STRING), diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala index bd502a56974..38d9b1e11b0 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala @@ -4,7 +4,7 @@ import java.nio.charset.StandardCharsets import java.util.concurrent.{ThreadLocalRandom, TimeUnit} import cats.Id -import cats.syntax.bifunctor._ +import cats.syntax.bifunctor.* import com.wavesplatform.account import com.wavesplatform.account.PublicKey import com.wavesplatform.common.state.ByteStr @@ -13,18 +13,19 @@ import com.wavesplatform.crypto.Curve25519 import com.wavesplatform.lang.directives.DirectiveSet import com.wavesplatform.lang.directives.values.{Account, DApp, V4} import com.wavesplatform.lang.script.Script -import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark._ +import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark.* import com.wavesplatform.lang.v1.compiler.Terms.{CONST_STRING, EVALUATED, EXPR, FUNCTION_CALL} +import com.wavesplatform.lang.v1.evaluator.Log import com.wavesplatform.lang.v1.evaluator.ctx.EvaluationContext import com.wavesplatform.lang.v1.evaluator.ctx.impl.EnvironmentFunctions import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.{Functions, WavesContext} -import com.wavesplatform.lang.v1.traits._ +import com.wavesplatform.lang.v1.traits.* import com.wavesplatform.lang.v1.traits.domain.Recipient.Address import com.wavesplatform.lang.v1.traits.domain.{BlockInfo, Recipient, ScriptAssetInfo, Tx} import com.wavesplatform.lang.{Common, Global, ValidationError} import com.wavesplatform.wallet.Wallet import monix.eval.Coeval -import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole import scala.util.Random @@ -88,7 +89,7 @@ class EnvironmentFunctionsBenchmark { @Benchmark def addressFromString(st: AddressFromString, bh: Blackhole): Unit = { val i = Random.nextInt(100) - bh.consume(eval(st.ctx, st.expr(i), V4, true)) + bh.consume(eval(st.ctx, st.expr(i), V4)) } } @@ -130,14 +131,15 @@ object EnvironmentFunctionsBenchmark { Right(Address(ByteStr(PublicKey(publicKey).toAddress.bytes))) override def accountScript(addressOrAlias: Recipient): Option[Script] = ??? - override def callScript( + + def callScript( dApp: Address, func: String, args: List[EVALUATED], payments: Seq[(Option[Array[Byte]], Long)], availableComplexity: Int, reentrant: Boolean - ): Coeval[(Either[ValidationError, EVALUATED], Int)] = ??? + ): Coeval[Id[(Either[ValidationError, (EVALUATED, Log[Id])], Int)]] = ??? } val environmentFunctions = new EnvironmentFunctions(environment) diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala index 5e54cd583e2..93042b254d1 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala @@ -5,21 +5,22 @@ import java.util.concurrent.TimeUnit import cats.Id import com.wavesplatform.lang.Common import com.wavesplatform.lang.directives.values.{V1, V3} -import com.wavesplatform.lang.v1.EvaluatorV2Benchmark._ +import com.wavesplatform.lang.v1.EvaluatorV2Benchmark.* import com.wavesplatform.lang.v1.compiler.Terms.{EXPR, IF, TRUE} import com.wavesplatform.lang.v1.compiler.TestCompiler -import com.wavesplatform.lang.v1.evaluator.ctx.EvaluationContext +import com.wavesplatform.lang.v1.evaluator.EvaluatorV2 +import com.wavesplatform.lang.v1.evaluator.ctx.{EvaluationContext, LoggedEvaluationContext} import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext import com.wavesplatform.lang.v1.traits.Environment -import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole import scala.annotation.tailrec object EvaluatorV2Benchmark { - val pureContext: CTX[Environment] = PureContext.build(V1, useNewPowPrecision = true, useNewPowPrecision = true).withEnvironment[Environment] + val pureContext: CTX[Environment] = PureContext.build(V1, useNewPowPrecision = true).withEnvironment[Environment] val pureEvalContext: EvaluationContext[Environment, Id] = pureContext.evaluationContext(Common.emptyBlockchainEnvironment()) - val evaluatorV2: EvaluatorV2 = new EvaluatorV2(LoggedEvaluationContext(_ => _ => (), pureEvalContext), V1, true) + val evaluatorV2: EvaluatorV2 = new EvaluatorV2(LoggedEvaluationContext(_ => _ => (), pureEvalContext), V1, true, true) } @OutputTimeUnit(TimeUnit.MILLISECONDS) diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/FoldBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/FoldBenchmark.scala index 941e880d9c0..90c9fa685bd 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/FoldBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/FoldBenchmark.scala @@ -46,7 +46,7 @@ class FoldBenchmark { @State(Scope.Benchmark) class FoldSt { val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) + val ctx = lazyContexts((ds, true)).value().evaluationContext(Common.emptyBlockchainEnvironment()) val function = "func f(acc: Boolean, elem: ByteVector) = acc && sigVerify(elem, base58'', base58'')" diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionBigIntBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionBigIntBenchmark.scala index 6fa1c468f7d..a781505c3a4 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionBigIntBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionBigIntBenchmark.scala @@ -10,7 +10,7 @@ import com.wavesplatform.lang.v1.FunctionHeader.Native import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BIGINT, FUNCTION_CALL} import com.wavesplatform.lang.v1.evaluator.FunctionIds.{FRACTION_BIGINT, FRACTION_BIGINT_ROUNDS} import com.wavesplatform.lang.v1.evaluator.ctx.impl.{PureContext, Rounding} -import org.openjdk.jmh.annotations.{State, _} +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole @OutputTimeUnit(TimeUnit.MICROSECONDS) @@ -42,7 +42,7 @@ class FractionBigIntBenchmark { @State(Scope.Benchmark) class FractionBigIntSt { val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) + val ctx = lazyContexts(ds -> true).value().evaluationContext(Common.emptyBlockchainEnvironment()) val max = CONST_BIGINT(PureContext.BigIntMax) val halfMax = CONST_BIGINT(PureContext.BigIntMax / 2) @@ -62,7 +62,7 @@ class FractionBigIntSt { val expr3 = FUNCTION_CALL( Native(FRACTION_BIGINT), - List(maxSqrt, maxSqrt, maxSqrt) + List(maxSqrt, maxSqrt, three) ) val expr1Round = FUNCTION_CALL( diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionIntBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionIntBenchmark.scala index 82ccbee348d..8d67d71f904 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionIntBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/FractionIntBenchmark.scala @@ -4,11 +4,12 @@ import java.util.concurrent.TimeUnit import com.wavesplatform.lang.Common import com.wavesplatform.lang.directives.DirectiveSet -import com.wavesplatform.lang.directives.values.{Account, Expression, V6} +import com.wavesplatform.lang.directives.values.{Account, Expression, V5, V6} import com.wavesplatform.lang.utils.lazyContexts -import com.wavesplatform.lang.v1.compiler.Terms.EXPR import com.wavesplatform.lang.v1.compiler.TestCompiler -import org.openjdk.jmh.annotations.{State, _} +import com.wavesplatform.lang.v1.evaluator.ContractEvaluator.LogExtraInfo +import com.wavesplatform.lang.v1.evaluator.EvaluatorV2 +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole @OutputTimeUnit(TimeUnit.MICROSECONDS) @@ -19,22 +20,22 @@ import org.openjdk.jmh.infra.Blackhole @Measurement(iterations = 10, time = 1) class FractionIntBenchmark { @Benchmark - def fraction1(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1, V5, true)) + def fraction1(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1, LogExtraInfo(), V5, true, true)) @Benchmark - def fraction2(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2, V5, true)) + def fraction2(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2, LogExtraInfo(), V5, true, true)) @Benchmark - def fraction3(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3, V5, true)) + def fraction3(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3, LogExtraInfo(), V5, true, true)) @Benchmark - def fraction1Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1Round, V5, true)) + def fraction1Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1Round, LogExtraInfo(), V5, true, true)) @Benchmark - def fraction2Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2Round, V5, true)) + def fraction2Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2Round, LogExtraInfo(), V5, true, true)) @Benchmark - def fraction3Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3Round, V5, true)) + def fraction3Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3Round, LogExtraInfo(), V5, true, true)) } @State(Scope.Benchmark) @@ -45,11 +46,11 @@ class St { val max = Long.MaxValue val maxSqrt = 3037000499L - val expr1 = TestCompiler(V6).compileExpression(s"fraction($max / 2, 3, 3)").expr.asInstanceOf[EXPR] - val expr2 = TestCompiler(V6).compileExpression(s"fraction($max, -$max, -$max)").expr.asInstanceOf[EXPR] - val expr3 = TestCompiler(V6).compileExpression(s"fraction($maxSqrt, $maxSqrt, $maxSqrt)").expr.asInstanceOf[EXPR] + val expr1 = TestCompiler(V6).compileExpression(s"fraction($max / 2, 3, 3)").expr + val expr2 = TestCompiler(V6).compileExpression(s"fraction($max, -$max, -$max)").expr + val expr3 = TestCompiler(V6).compileExpression(s"fraction($maxSqrt, $maxSqrt, $maxSqrt)").expr - val expr1Round = TestCompiler(V6).compileExpression(s"fraction($max / 2, 3, 3, HALFEVEN)").expr.asInstanceOf[EXPR] - val expr2Round = TestCompiler(V6).compileExpression(s"fraction($max, -$max, -$max, HALFEVEN)").expr.asInstanceOf[EXPR] - val expr3Round = TestCompiler(V6).compileExpression(s"fraction($maxSqrt, $maxSqrt, $maxSqrt, HALFEVEN)").expr.asInstanceOf[EXPR] + val expr1Round = TestCompiler(V6).compileExpression(s"fraction($max / 2, 3, 3, HALFEVEN)").expr + val expr2Round = TestCompiler(V6).compileExpression(s"fraction($max, -$max, -$max, HALFEVEN)").expr + val expr3Round = TestCompiler(V6).compileExpression(s"fraction($maxSqrt, $maxSqrt, $maxSqrt, HALFEVEN)").expr } diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ListIndexOfBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ListIndexOfBenchmark.scala index 84d9d683f31..fff55fcfaf5 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ListIndexOfBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ListIndexOfBenchmark.scala @@ -6,7 +6,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.lang.v1.ListIndexOfBenchmark.ListIndexOfSt import com.wavesplatform.lang.v1.compiler.Terms.{CONST_STRING, EVALUATED} import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext -import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole @OutputTimeUnit(TimeUnit.MICROSECONDS) @@ -41,10 +41,10 @@ object ListIndexOfBenchmark { val listWithMaxCmpWeightElements = IndexedSeq.fill(1000)(CONST_STRING("a" * (ContractLimits.MaxCmpWeight.toInt - 1) + "b").explicitGet()) val listWithMaxSizeElements = IndexedSeq.fill(1000)(CONST_STRING(("a" * (150 * 1024 - 1)) + "b").explicitGet()) - def indexOf(list: Seq[EVALUATED], element: EVALUATED): Either[String, EVALUATED] = + def indexOf(list: Seq[EVALUATED], element: EVALUATED) = PureContext.genericListIndexOf(element, list.indexOf, list.indexWhere) - def lastIndexOf(list: Seq[EVALUATED], element: EVALUATED): Either[String, EVALUATED] = + def lastIndexOf(list: Seq[EVALUATED], element: EVALUATED) = PureContext.genericListIndexOf(element, list.lastIndexOf(_), list.lastIndexWhere) } } diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowBigIntBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowBigIntBenchmark.scala index 1fe76d638be..4dd18892968 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowBigIntBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowBigIntBenchmark.scala @@ -51,7 +51,7 @@ class PowBigIntBenchmark { @State(Scope.Benchmark) class PowBigIntSt { val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) + val ctx = lazyContexts(ds -> true).value().evaluationContext(Common.emptyBlockchainEnvironment()) val max = PureContext.BigIntMax val min = PureContext.BigIntMin diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowIntBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowIntBenchmark.scala index 4dff1649aca..568d2017025 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowIntBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/PowIntBenchmark.scala @@ -8,7 +8,7 @@ import com.wavesplatform.lang.directives.values.{Account, Expression, V5} import com.wavesplatform.lang.utils.lazyContexts import com.wavesplatform.lang.v1.compiler.Terms.EXPR import com.wavesplatform.lang.v1.compiler.TestCompiler -import org.openjdk.jmh.annotations.{State, _} +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole @OutputTimeUnit(TimeUnit.MICROSECONDS) @@ -52,7 +52,7 @@ class PowIntBenchmark { @State(Scope.Benchmark) class PowIntSt { val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) + val ctx = lazyContexts((ds, true)).value().evaluationContext(Common.emptyBlockchainEnvironment()) val max = Long.MaxValue diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/PureFunctionsRebenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/PureFunctionsRebenchmark.scala index 5ed10c8c78e..6b731b0b82e 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/PureFunctionsRebenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/PureFunctionsRebenchmark.scala @@ -218,14 +218,14 @@ class PureFunctionsRebenchmark { object PureFunctionsRebenchmark { val context: EvaluationContext[Environment, Id] = - lazyContexts(DirectiveSet(V5, Account, Expression).explicitGet())() + lazyContexts(DirectiveSet(V5, Account, Expression).explicitGet() -> true)() .evaluationContext(Common.emptyBlockchainEnvironment()) val eval: EXPR => (Log[Id], Int, Either[ExecutionError, EVALUATED]) = - v1.eval(context, _, V4, true) + v1.eval(context, _, V4) val evalV5: EXPR => (Log[Id], Int, Either[ExecutionError, EVALUATED]) = - v1.eval(context, _, V5, true) + v1.eval(context, _, V5) def randomBytes(length: Int): Array[Byte] = { val bytes = new Array[Byte](length) diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala index 8d877836b35..1ebc949f183 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala @@ -11,15 +11,15 @@ import com.wavesplatform.lang.Global import com.wavesplatform.lang.directives.values.{V1, V4} import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark.{curve25519, randomBytes} import com.wavesplatform.lang.v1.FunctionHeader.Native -import com.wavesplatform.lang.v1.ScriptEvaluatorBenchmark._ -import com.wavesplatform.lang.v1.compiler.Terms._ +import com.wavesplatform.lang.v1.ScriptEvaluatorBenchmark.* +import com.wavesplatform.lang.v1.compiler.Terms.* import com.wavesplatform.lang.v1.evaluator.Contextful.NoContext -import com.wavesplatform.lang.v1.evaluator.EvaluatorV1._ +import com.wavesplatform.lang.v1.evaluator.EvaluatorV1.* import com.wavesplatform.lang.v1.evaluator.FunctionIds.{FROMBASE58, SIGVERIFY, TOBASE58} import com.wavesplatform.lang.v1.evaluator.ctx.EvaluationContext import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, PureContext} import com.wavesplatform.lang.v1.evaluator.{EvaluatorV1, FunctionIds} -import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole import scala.util.Random @@ -27,7 +27,7 @@ import scala.util.Random object ScriptEvaluatorBenchmark { val version = V1 val pureEvalContext: EvaluationContext[NoContext, Id] = - PureContext.build(V1, useNewPowPrecision = true, useNewPowPrecision = true).evaluationContext + PureContext.build(V1, useNewPowPrecision = true).evaluationContext val evaluatorV1: EvaluatorV1[Id, NoContext] = new EvaluatorV1[Id, NoContext]() } @@ -112,8 +112,8 @@ class Base58Perf { val encode: EXPR = { val base58Count = 120 - val sum = (1 to base58Count).foldRight[EXPR](CONST_LONG(0)) { - case (i, e) => FUNCTION_CALL(PureContext.sumLong, List(REF("v" + i), e)) + val sum = (1 to base58Count).foldRight[EXPR](CONST_LONG(0)) { case (i, e) => + FUNCTION_CALL(PureContext.sumLong, List(REF("v" + i), e)) } (1 to base58Count) .map { i => @@ -132,8 +132,8 @@ class Base58Perf { val decode: EXPR = { val base58Count = 60 - val sum = (1 to base58Count).foldRight[EXPR](CONST_LONG(0)) { - case (i, e) => FUNCTION_CALL(PureContext.sumLong, List(REF("v" + i), e)) + val sum = (1 to base58Count).foldRight[EXPR](CONST_LONG(0)) { case (i, e) => + FUNCTION_CALL(PureContext.sumLong, List(REF("v" + i), e)) } (1 to base58Count) .map { i => @@ -155,8 +155,8 @@ class Signatures { val expr: EXPR = { val sigCount = 20 - val sum = (1 to sigCount).foldRight[EXPR](CONST_LONG(0)) { - case (i, e) => FUNCTION_CALL(PureContext.sumLong, List(REF("v" + i), e)) + val sum = (1 to sigCount).foldRight[EXPR](CONST_LONG(0)) { case (i, e) => + FUNCTION_CALL(PureContext.sumLong, List(REF("v" + i), e)) } (1 to sigCount) .map { i => @@ -183,8 +183,8 @@ class Signatures { ) ) } - .foldRight[EXPR](FUNCTION_CALL(PureContext.eq, List(sum, CONST_LONG(sigCount)))) { - case (let, e) => BLOCK(let, e) + .foldRight[EXPR](FUNCTION_CALL(PureContext.eq, List(sum, CONST_LONG(sigCount)))) { case (let, e) => + BLOCK(let, e) } } } @@ -196,8 +196,8 @@ class Concat { private val Steps = 180 private def expr(init: EXPR, func: FunctionHeader, operand: EXPR, count: Int) = - (1 to count).foldLeft[EXPR](init) { - case (e, _) => FUNCTION_CALL(func, List(e, operand)) + (1 to count).foldLeft[EXPR](init) { case (e, _) => + FUNCTION_CALL(func, List(e, operand)) } val strings: EXPR = expr( @@ -218,7 +218,7 @@ class Concat { @State(Scope.Benchmark) class Median { - val context: EvaluationContext[NoContext, Id] = PureContext.build(V4, useNewPowPrecision = true, useNewPowPrecision = true).evaluationContext + val context: EvaluationContext[NoContext, Id] = PureContext.build(V4, useNewPowPrecision = true).evaluationContext val randomElements: Array[EXPR] = (1 to 10000).map { _ => @@ -261,9 +261,7 @@ class Median { @State(Scope.Benchmark) class SigVerify32Kb { val context: EvaluationContext[NoContext, Id] = - Monoid.combine( - PureContext.build(V4, useNewPowPrecision = true, useNewPowPrecision =true).evaluationContext, - CryptoContext.build(Global, V4).evaluationContext) + Monoid.combine(PureContext.build(V4, useNewPowPrecision = true).evaluationContext, CryptoContext.build(Global, V4).evaluationContext) val expr: EXPR = { val (privateKey, publicKey) = curve25519.generateKeypair @@ -285,7 +283,7 @@ class SigVerify32Kb { class ListRemoveByIndex { val context: EvaluationContext[NoContext, Id] = Monoid.combine( - PureContext.build(V4, useNewPowPrecision = true, useNewPowPrecision = true).evaluationContext, + PureContext.build(V4, useNewPowPrecision = true).evaluationContext, CryptoContext.build(Global, V4).evaluationContext ) diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtCbrtBigIntBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtCbrtBigIntBenchmark.scala index 2a7657854fd..e83bee310ae 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtCbrtBigIntBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtCbrtBigIntBenchmark.scala @@ -33,7 +33,7 @@ class SqrtCbrtBigIntBenchmark { @State(Scope.Benchmark) class SqrtBigIntSt { val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) + val ctx = lazyContexts(ds -> true).value().evaluationContext(Common.emptyBlockchainEnvironment()) val max = PureContext.BigIntMax val min = PureContext.BigIntMin diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtIntBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtIntBenchmark.scala index 67ec4cd0d69..40da5f2e3b7 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtIntBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/SqrtIntBenchmark.scala @@ -8,7 +8,7 @@ import com.wavesplatform.lang.directives.values.{Account, Expression, V5} import com.wavesplatform.lang.utils.lazyContexts import com.wavesplatform.lang.v1.compiler.Terms.EXPR import com.wavesplatform.lang.v1.compiler.TestCompiler -import org.openjdk.jmh.annotations.{State, _} +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole @OutputTimeUnit(TimeUnit.MICROSECONDS) @@ -28,7 +28,7 @@ class SqrtIntBenchmark { @State(Scope.Benchmark) class SqrtIntSt { val ds = DirectiveSet(V5, Account, Expression).fold(null, identity) - val ctx = lazyContexts(ds).value().evaluationContext(Common.emptyBlockchainEnvironment()) + val ctx = lazyContexts(ds -> true).value().evaluationContext(Common.emptyBlockchainEnvironment()) val expr1 = compile(s"pow(${Long.MaxValue}, 0, 5, 1, 8, DOWN)") val expr2 = compile(s"pow(${Long.MaxValue}, 8, 5, 1, 8, DOWN)") diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala index 586b8c9a9a1..aeed9077baf 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala @@ -5,6 +5,7 @@ import com.wavesplatform.lang.directives.values.StdLibVersion import com.wavesplatform.lang.v1.FunctionHeader.Native import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BIGINT, CONST_LONG, EXPR, FUNCTION_CALL} +import com.wavesplatform.lang.v1.evaluator.ContractEvaluator.LogExtraInfo import com.wavesplatform.lang.v1.evaluator.FunctionIds.POW_BIGINT import com.wavesplatform.lang.v1.evaluator.ctx.EvaluationContext import com.wavesplatform.lang.v1.evaluator.ctx.impl.Rounding @@ -30,5 +31,5 @@ package object v1 { expr: EXPR, stdLibVersion: StdLibVersion ): (Log[Id], Int, Either[ExecutionError, Terms.EVALUATED]) = - EvaluatorV2.applyCompleted(ctx, expr, stdLibVersion, newMode = true, correctFunctionCallScope = true) + EvaluatorV2.applyCompleted(ctx, expr, LogExtraInfo(), stdLibVersion, newMode = true, correctFunctionCallScope = true) } diff --git a/benchmark/src/test/scala/com/wavesplatform/serialization/protobuf/SmartNoSmartBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/serialization/protobuf/SmartNoSmartBenchmark.scala index 51419433561..7c976ed47a9 100644 --- a/benchmark/src/test/scala/com/wavesplatform/serialization/protobuf/SmartNoSmartBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/serialization/protobuf/SmartNoSmartBenchmark.scala @@ -4,11 +4,11 @@ import java.util.concurrent.TimeUnit import com.wavesplatform.account.{AddressScheme, PublicKey} import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils._ +import com.wavesplatform.common.utils.* import com.wavesplatform.serialization.protobuf.SmartNoSmartBenchmark.ExchangeTransactionSt -import com.wavesplatform.transaction.assets.exchange._ -import com.wavesplatform.transaction.{Proofs, TxVersion} -import org.openjdk.jmh.annotations._ +import com.wavesplatform.transaction.assets.exchange.* +import com.wavesplatform.transaction.{Proofs, TxExchangeAmount, TxExchangePrice, TxMatcherFee, TxOrderPrice, TxPositiveAmount, TxVersion} +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole //noinspection ScalaStyle @@ -21,15 +21,27 @@ import org.openjdk.jmh.infra.Blackhole class SmartNoSmartBenchmark { @Benchmark def smartExchangeTX_test(st: ExchangeTransactionSt, bh: Blackhole): Unit = { - import st._ + import st.* val exchangeTransaction = ExchangeTransaction.create(TxVersion.V2, buy, sell, 2, 5000000000L, 1, 1, 1, 1526992336241L, proofs) bh.consume(exchangeTransaction.explicitGet()) } @Benchmark def unsafeExchangeTX_test(st: ExchangeTransactionSt, bh: Blackhole): Unit = { - import st._ - val exchangeTransaction = ExchangeTransaction(TxVersion.V2, buy, sell, 2, 5000000000L, 1, 1, 1, 1526992336241L, proofs, AddressScheme.current.chainId) + import st.* + val exchangeTransaction = ExchangeTransaction( + TxVersion.V2, + buy, + sell, + TxExchangeAmount.unsafeFrom(2), + TxExchangePrice.unsafeFrom(5000000000L), + 1, + 1, + TxPositiveAmount.unsafeFrom(1), + 1526992336241L, + proofs, + AddressScheme.current.chainId + ) bh.consume(exchangeTransaction) } } @@ -37,9 +49,37 @@ class SmartNoSmartBenchmark { object SmartNoSmartBenchmark { @State(Scope.Benchmark) class ExchangeTransactionSt { - val buy = Order(TxVersion.V2, PublicKey.fromBase58String("BqeJY8CP3PeUDaByz57iRekVUGtLxoow4XxPvXfHynaZ").explicitGet(), PublicKey.fromBase58String("Fvk5DXmfyWVZqQVBowUBMwYtRAHDtdyZNNeRrwSjt6KP").explicitGet(), AssetPair.createAssetPair("WAVES", "9ZDWzK53XT5bixkmMwTJi2YzgxCqn5dUajXFcT2HcFDy").get, OrderType.BUY, 2, 6000000000L, 1526992336241L, 1529584336241L, 1, proofs = Proofs(Seq(ByteStr.decodeBase58("2bkuGwECMFGyFqgoHV4q7GRRWBqYmBFWpYRkzgYANR4nN2twgrNaouRiZBqiK2RJzuo9NooB9iRiuZ4hypBbUQs").get))) + val buy = Order( + TxVersion.V2, + OrderAuthentication.OrderProofs( + PublicKey.fromBase58String("BqeJY8CP3PeUDaByz57iRekVUGtLxoow4XxPvXfHynaZ").explicitGet(), + Proofs(Seq(ByteStr.decodeBase58("2bkuGwECMFGyFqgoHV4q7GRRWBqYmBFWpYRkzgYANR4nN2twgrNaouRiZBqiK2RJzuo9NooB9iRiuZ4hypBbUQs").get)) + ), + PublicKey.fromBase58String("Fvk5DXmfyWVZqQVBowUBMwYtRAHDtdyZNNeRrwSjt6KP").explicitGet(), + AssetPair.createAssetPair("WAVES", "9ZDWzK53XT5bixkmMwTJi2YzgxCqn5dUajXFcT2HcFDy").get, + OrderType.BUY, + TxExchangeAmount.unsafeFrom(2), + TxOrderPrice.unsafeFrom(6000000000L), + 1526992336241L, + 1529584336241L, + TxMatcherFee.unsafeFrom(1) + ) - val sell = Order(TxVersion.V1, PublicKey.fromBase58String("7E9Za8v8aT6EyU1sX91CVK7tWUeAetnNYDxzKZsyjyKV").explicitGet(), PublicKey.fromBase58String("Fvk5DXmfyWVZqQVBowUBMwYtRAHDtdyZNNeRrwSjt6KP").explicitGet(), AssetPair.createAssetPair("WAVES", "9ZDWzK53XT5bixkmMwTJi2YzgxCqn5dUajXFcT2HcFDy").get, OrderType.SELL, 3, 5000000000L, 1526992336241L, 1529584336241L, 2, proofs = Proofs(ByteStr.decodeBase58("2R6JfmNjEnbXAA6nt8YuCzSf1effDS4Wkz8owpCD9BdCNn864SnambTuwgLRYzzeP5CAsKHEviYKAJ2157vdr5Zq").get)) + val sell = Order( + TxVersion.V1, + OrderAuthentication.OrderProofs( + PublicKey.fromBase58String("7E9Za8v8aT6EyU1sX91CVK7tWUeAetnNYDxzKZsyjyKV").explicitGet(), + Proofs(ByteStr.decodeBase58("2R6JfmNjEnbXAA6nt8YuCzSf1effDS4Wkz8owpCD9BdCNn864SnambTuwgLRYzzeP5CAsKHEviYKAJ2157vdr5Zq").get) + ), + PublicKey.fromBase58String("Fvk5DXmfyWVZqQVBowUBMwYtRAHDtdyZNNeRrwSjt6KP").explicitGet(), + AssetPair.createAssetPair("WAVES", "9ZDWzK53XT5bixkmMwTJi2YzgxCqn5dUajXFcT2HcFDy").get, + OrderType.SELL, + TxExchangeAmount.unsafeFrom(3), + TxOrderPrice.unsafeFrom(5000000000L), + 1526992336241L, + 1529584336241L, + TxMatcherFee.unsafeFrom(2) + ) val proofs = Proofs(Seq(ByteStr.decodeBase58("5NxNhjMrrH5EWjSFnVnPbanpThic6fnNL48APVAkwq19y2FpQp4tNSqoAZgboC2ykUfqQs9suwBQj6wERmsWWNqa").get)) } diff --git a/build.sbt b/build.sbt index 89e4ac79904..027fd51327a 100644 --- a/build.sbt +++ b/build.sbt @@ -194,7 +194,6 @@ checkPRRaw := Def .sequential( `waves-node` / clean, Def.task { - (Test / compile).value (`lang-tests` / Test / test).value (`repl-jvm` / Test / test).value (`lang-js` / Compile / fastOptJS).value @@ -203,6 +202,7 @@ checkPRRaw := Def (node / Test / test).value (`repl-js` / Compile / fastOptJS).value (`node-it` / Test / compile).value + (benchmark / Test / compile).value } ) .value