Skip to content

Commit

Permalink
speedy compilation benchmark (#11852)
Browse files Browse the repository at this point in the history
CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
nickchapman-da authored Nov 24, 2021
1 parent 393893a commit 0374843
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions daml-lf/interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

load(
"//bazel_tools:scala.bzl",
"da_scala_benchmark_jmh",
"da_scala_library",
"da_scala_test",
"da_scala_test_suite",
Expand Down Expand Up @@ -107,3 +108,29 @@ scala_repl(
":interpreter",
],
)

da_scala_benchmark_jmh(
name = "speedy-compilation-benchmark",
srcs = glob(["src/bench/**/*.scala"]),
data = [
"//ledger/test-common:model-tests-1.14.dar",
],
scala_deps = [
"@maven//:org_scalaz_scalaz_core",
],
visibility = ["//visibility:public"],
deps = [
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/archive:daml_lf_archive_reader",
"//daml-lf/archive:daml_lf_dev_archive_proto_java",
"//daml-lf/data",
"//daml-lf/engine",
"//daml-lf/interpreter",
"//daml-lf/language",
"//daml-lf/scenario-interpreter",
"//daml-lf/transaction",
"//daml-lf/validation",
"//ledger/test-common:dar-files-default-lib",
"@maven//:com_google_protobuf_protobuf_java",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.lf.speedy

import com.daml.bazeltools.BazelRunfiles.rlocation
import com.daml.ledger.test.ModelTestDar
import com.daml.lf.archive.DarDecoder
import com.daml.lf.archive.Dar
import com.daml.lf.data.Ref.PackageId
import com.daml.lf.language.Ast.Package
import com.daml.lf.language.PackageInterface
import com.daml.lf.speedy
import java.io.File
import org.openjdk.jmh.annotations.{Param, Setup, Level, Benchmark, State, Scope}

@State(Scope.Benchmark)
class SpeedyCompilation {

@Param(Array(""))
var darPath: String = _

private var dar: Dar[(PackageId, Package)] = _
private var darMap: Map[PackageId, Package] = _
private var interface: PackageInterface = _

@Setup(Level.Trial)
def setup(): Unit = {
val darFile = new File(
if (darPath.isEmpty)
rlocation(ModelTestDar.path)
else darPath
)
dar = DarDecoder.assertReadArchiveFromFile(darFile)
darMap = dar.all.toMap
interface = PackageInterface(darMap)
}

@Benchmark
def bench(): Unit = {
val config = speedy.Compiler.Config.Default
val res = speedy.Compiler.compilePackages(interface, darMap, config)
assert(res.isRight)
}
}

0 comments on commit 0374843

Please sign in to comment.