Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE-2163: Optimize monitor usage in JNA #3503

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .github/workflows/check-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check PR
on: [push]
jobs:
check-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache SBT
uses: actions/cache@v1
with:
path: ~/.sbt
key: sbt-cache-${{ hashFiles('project/build.properties') }}
- name: Cache Coursier
uses: actions/cache@v1
with:
path: ~/.cache/coursier
key: coursier-cache
- name: Check PR
run: |
sbt --mem 6144 --batch checkPR
find ~/.cache/coursier -type d -name '*SNAPSHOT' | xargs rm -vrf {} \;
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.idea
.ensime
.ensime_cache/
.bsp

# scala build folders and files
target
Expand Down
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion benchmark/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
enablePlugins(JmhPlugin)

Jmh / version := "1.32"

libraryDependencies ++= Seq(
"org.scodec" %% "scodec-core" % "1.11.7"
"org.scodec" %% "scodec-core" % "1.11.8"
) ++ Dependencies.logDeps

// https://github.com/ktoso/sbt-jmh#adding-to-your-project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.util.concurrent.TimeUnit

import com.wavesplatform.account.{Address, PublicKey}
import com.wavesplatform.common.AddressBenchmark.{CachedAddress, PublicKeySt, UncachedAddress}
import com.wavesplatform.crypto.Curve25519
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole

Expand Down Expand Up @@ -37,7 +38,7 @@ class AddressBenchmark {
object AddressBenchmark {
@State(Scope.Benchmark)
class PublicKeySt {
val publicKey = new Array[Byte](scorex.crypto.signatures.Curve25519.KeyLength25519)
val publicKey = new Array[Byte](Curve25519.KeyLength)
Random.nextBytes(publicKey)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.wavesplatform.common

import java.util.concurrent.TimeUnit

import com.google.common.io.BaseEncoding
import com.wavesplatform.common.EcrecoverBenchmark.{EcrecoverSt1, EcrecoverSt2}
import com.wavesplatform.crypto.Keccak256
import com.wavesplatform.lang.Global
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import scorex.crypto.hash.Keccak256
import scorex.util.encode.Base16

@OutputTimeUnit(TimeUnit.MICROSECONDS)
@BenchmarkMode(Array(Mode.AverageTime))
Expand All @@ -29,19 +29,23 @@ class EcrecoverBenchmark {
object EcrecoverBenchmark {
@State(Scope.Benchmark)
class EcrecoverSt1 {
val signature = Base16.decode(
"848ffb6a07e7ce335a2bfe373f1c17573eac320f658ea8cf07426544f2203e9d52dbba4584b0b6c0ed5333d84074002878082aa938fdf68c43367946b2f615d01b"
).get
val signature = BaseEncoding
.base16()
.decode(
"848ffb6a07e7ce335a2bfe373f1c17573eac320f658ea8cf07426544f2203e9d52dbba4584b0b6c0ed5333d84074002878082aa938fdf68c43367946b2f615d01b"
)
val message = "i am the owner"
val prefix = "\u0019Ethereum Signed Message:\n" + message.length
val messageHash = Keccak256.hash((prefix + message).getBytes)
}

@State(Scope.Benchmark)
class EcrecoverSt2 {
val signature = Base16.decode(
"3b163bbd90556272b57c35d1185b46824f8e16ca229bdb36f8dfd5eaaee9420723ef7bc3a6c0236568217aa990617cf292b1bef1e7d1d936fb2faef3d846c5751b"
).get
val signature = BaseEncoding
.base16()
.decode(
"3b163bbd90556272b57c35d1185b46824f8e16ca229bdb36f8dfd5eaaee9420723ef7bc3a6c0236568217aa990617cf292b1bef1e7d1d936fb2faef3d846c5751b"
)
val message = "what's up jim"
val prefix = "\u0019Ethereum Signed Message:\n" + message.length
val messageHash = Keccak256.hash((prefix + message).getBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package com.wavesplatform.common
import java.util.concurrent.TimeUnit

import com.google.common.primitives.Ints
import com.wavesplatform.common.merkle._
import com.wavesplatform.common.merkle.Merkle._
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.annotations.{Level => _, _}
import org.openjdk.jmh.infra.Blackhole
import scorex.crypto.authds.LeafData
import scorex.crypto.authds.merkle.MerkleTree
import scorex.crypto.hash.{Blake2b256, CryptographicHash32, Digest32}

import scala.util.Random

Expand Down Expand Up @@ -50,22 +48,16 @@ class MerkleBenchmark {
}

object MerkleBenchmark {
implicit val fastHash = new CryptographicHash32 {
override def hash(input: Message): Digest32 = Blake2b256.hash(input)
}

def testData(deep: Int): (MerkleTree[Digest32], List[LeafData]) = {
def testData(deep: Int): (Seq[Level], List[LeafData]) = {
val n = BigInt(2).pow(deep - 1).toInt
val size = n + 1 + Random.nextInt(n)
val data: List[LeafData] =
List
.fill(size)(Random.nextInt(10000))
.map(Ints.toByteArray)
.map(LeafData @@ _)

val tree = MerkleTree[Digest32](data)(fastHash)

(tree, data)
(mkLevels(data), data)
}

class MerkleDeep(size: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.wavesplatform.common
import java.util.concurrent.TimeUnit

import com.wavesplatform.common.SigVerifyBenchmark._
import com.wavesplatform.crypto.Curve25519
import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark.{curve25519, randomBytes}
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import scorex.crypto.signatures.{Curve25519, Signature}

@OutputTimeUnit(TimeUnit.MICROSECONDS)
@BenchmarkMode(Array(Mode.AverageTime))
Expand All @@ -17,52 +17,52 @@ import scorex.crypto.signatures.{Curve25519, Signature}
class SigVerifyBenchmark {
@Benchmark
def sigVerify_128b(st: CurveSt128b, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_1Kb(st: CurveSt1Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_5Kb(st: CurveSt5Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_6Kb(st: CurveSt6Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_7Kb(st: CurveSt7Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_8Kb(st: CurveSt8Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_16Kb(st: CurveSt16Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_32Kb(st: CurveSt32Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_64Kb(st: CurveSt64Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_128Kb(st: CurveSt128Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

@Benchmark
def sigVerify_150Kb(st: CurveSt150Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

// For DataTransaction.MaxProtoBytes
@Benchmark
def sigVerify_162Kb(st: CurveSt162Kb, bh: Blackhole): Unit =
bh.consume(Curve25519.verify(Signature @@ st.signature, st.message, st.publicKey))
bh.consume(Curve25519.verify(st.signature, st.message, st.publicKey))

}

Expand Down Expand Up @@ -105,7 +105,7 @@ object SigVerifyBenchmark {

class CurveSt(size: Int) {
val (privateKey, publicKey) = curve25519.generateKeypair
val message = randomBytes(size)
val signature = curve25519.sign(privateKey, message)
val message = randomBytes(size)
val signature = curve25519.sign(privateKey, message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.wavesplatform.lang.v1.traits.domain.Recipient.{Address, Alias}
import com.wavesplatform.lang.v1.traits.domain.{Issue, Lease}
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import scorex.crypto.hash.{Blake2b256, Keccak256, Sha256}
import com.wavesplatform.crypto.{Blake2b256, Keccak256, Sha256}

@OutputTimeUnit(TimeUnit.MICROSECONDS)
@BenchmarkMode(Array(Mode.AverageTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package com.wavesplatform.lang.v1

import java.nio.charset.StandardCharsets
import java.util.concurrent.{ThreadLocalRandom, TimeUnit}

import cats.Id
import cats.implicits._
import cats.syntax.bifunctor._
import com.wavesplatform.account
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
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
Expand All @@ -19,13 +21,11 @@ import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.{Functions, WavesConte
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}
import com.wavesplatform.lang.ValidationError
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.infra.Blackhole
import scorex.crypto.signatures.{Curve25519, PrivateKey, PublicKey, Signature}

import scala.util.Random

Expand Down Expand Up @@ -69,7 +69,7 @@ class EnvironmentFunctionsBenchmark {
def secureHash_test(): Array[Byte] = hashTest(Global.secureHash)

@Benchmark
def curve25519_generateKeypair_test(): (PrivateKey, PublicKey) = curve25519.generateKeypair
def curve25519_generateKeypair_test(): (Array[Byte], Array[Byte]) = curve25519.generateKeypair

@Benchmark
def curve25519_sign_full_test(): Array[Byte] = {
Expand All @@ -82,7 +82,7 @@ class EnvironmentFunctionsBenchmark {
val (privateKey, publicKey) = curve25519.generateKeypair
val message = randomBytes(DataBytesLength)
val signature = curve25519.sign(privateKey, message)
Curve25519.verify(Signature @@ signature, message, publicKey)
Curve25519.verify(signature, message, publicKey)
}

@Benchmark
Expand Down Expand Up @@ -128,8 +128,15 @@ object EnvironmentFunctionsBenchmark {
_.toString,
address => Address(ByteStr(address.bytes))
)
override def accountScript(addressOrAlias: Recipient): Option[Script] = ???
override def callScript(dApp: Address, func: String, args: List[EVALUATED], payments: Seq[(Option[Array[Byte]], Long)], availableComplexity: Int, reentrant: Boolean): Coeval[(Either[ValidationError, EVALUATED], Int)] = ???
override def accountScript(addressOrAlias: Recipient): Option[Script] = ???
override def callScript(
dApp: Address,
func: String,
args: List[EVALUATED],
payments: Seq[(Option[Array[Byte]], Long)],
availableComplexity: Int,
reentrant: Boolean
): Coeval[(Either[ValidationError, EVALUATED], Int)] = ???
}

val environmentFunctions = new EnvironmentFunctions(defaultEnvironment)
Expand All @@ -150,21 +157,23 @@ object EnvironmentFunctionsBenchmark {
def hashTest[T](len: Int, f: Array[Byte] => T): T = f(randomBytes(len))

object curve25519 {
def generateKeypair: (PrivateKey, PublicKey) = Curve25519.createKeyPair(randomBytes(SeedBytesLength))
def sign(privateKey: PrivateKey, message: Array[Byte]): Array[Byte] = Curve25519.sign(privateKey, message)
def generateKeypair = Curve25519.createKeyPair(randomBytes(SeedBytesLength))
def sign(privateKey: Array[Byte], message: Array[Byte]): Array[Byte] = Curve25519.sign(privateKey, message)
}
}

@State(Scope.Benchmark)
class AddressFromString {
val ctx: EvaluationContext[Environment, Id] =
WavesContext.build(Global, DirectiveSet(V4, Account, DApp).explicitGet())
WavesContext
.build(Global, DirectiveSet(V4, Account, DApp).explicitGet())
.evaluationContext(defaultEnvironment)

val expr: Array[EXPR] =
(1 to 100).map { _ =>
val address =
Wallet.generateNewAccount(Random.nextBytes(8), 1)
Wallet
.generateNewAccount(Random.nextBytes(8), 1)
.publicKey
.toAddress(ChainId)
.toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Funcs {
""".stripMargin

val parsed = Parser.parseExpr(script).get.value
val expr = ExpressionCompiler(pureContext.compilerContext, parsed).explicitGet()._1
val expr = ExpressionCompiler(pureContext.compilerContext, parsed).explicitGet()._1
}

@State(Scope.Benchmark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ class PureFunctionsRebenchmark {

object PureFunctionsRebenchmark {
val context: EvaluationContext[Environment, Id] =
Monoid.combine(
PureContext.build(V4, fixUnicodeFunctions = true).evaluationContext,
CryptoContext.build(Global, V4).evaluationContext
).asInstanceOf[EvaluationContext[Environment, Id]]
Monoid
.combine(
PureContext.build(V4, fixUnicodeFunctions = true).evaluationContext,
CryptoContext.build(Global, V4).evaluationContext
)
.asInstanceOf[EvaluationContext[Environment, Id]]

val eval: EXPR => (Log[Id], Int, Either[ExecutionError, EVALUATED]) =
EvaluatorV2.applyCompleted(context, _, V4)
Expand All @@ -252,7 +254,7 @@ object PureFunctionsRebenchmark {

@State(Scope.Benchmark)
class SplitString {
val separator = ","
val separator = ","
val separatedString = List.fill(1000)(Random.nextPrintableChar().toString * 31).mkString(separator)
val expr: EXPR =
FUNCTION_CALL(
Expand Down
Loading