-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from szeiger/sjsonnet-perf-improvements
Sjsonnet performance improvements
- Loading branch information
Showing
32 changed files
with
1,650 additions
and
1,209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package sjsonnet | ||
|
||
import java.io.{OutputStream, PrintStream} | ||
import java.util.concurrent.TimeUnit | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import org.openjdk.jmh.infra._ | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(4) | ||
@Threads(1) | ||
@Warmup(iterations = 30) | ||
@Measurement(iterations = 40) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
class MainBenchmark { | ||
|
||
val mainArgs = Array[String]( | ||
"../../universe2/rulemanager/deploy/rulemanager.jsonnet", | ||
"-J", "../../universe2", | ||
"-J", "../../universe2/mt-shards/dev/az-westus-c2", | ||
) | ||
|
||
val dummyOut = new PrintStream(new OutputStream { | ||
def write(b: Int): Unit = () | ||
override def write(b: Array[Byte]): Unit = () | ||
override def write(b: Array[Byte], off: Int, len: Int): Unit = () | ||
}) | ||
|
||
@Benchmark | ||
def main(bh: Blackhole): Unit = { | ||
bh.consume(SjsonnetMain.main0( | ||
mainArgs, | ||
collection.mutable.HashMap.empty, | ||
System.in, | ||
dummyOut, | ||
System.err, | ||
os.pwd, | ||
None | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
val sjsonnetVersion = "0.3.3" | ||
|
||
scalaVersion in Global := "2.13.4" | ||
|
||
cancelable in Global := true | ||
|
||
lazy val main = (project in file("sjsonnet")) | ||
.settings( | ||
scalacOptions in Compile ++= Seq("-opt:l:inline", "-opt-inline-from:sjsonnet.**"), | ||
fork in Test := true, | ||
baseDirectory in Test := (baseDirectory in ThisBuild).value, | ||
libraryDependencies ++= Seq( | ||
"com.lihaoyi" %% "fastparse" % "2.3.1", | ||
"com.lihaoyi" %% "pprint" % "0.6.1", | ||
"com.lihaoyi" %% "ujson" % "1.3.7", | ||
"com.lihaoyi" %% "scalatags" % "0.9.3", | ||
"com.lihaoyi" %% "os-lib" % "0.7.2", | ||
"com.lihaoyi" %% "mainargs" % "0.2.0", | ||
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.0", | ||
"org.tukaani" % "xz" % "1.8", | ||
), | ||
libraryDependencies ++= Seq( | ||
"com.lihaoyi" %% "utest" % "0.7.7", | ||
).map(_ % "test"), | ||
testFrameworks += new TestFramework("utest.runner.Framework"), | ||
(unmanagedSourceDirectories in Compile) := Seq( | ||
baseDirectory.value / "src", | ||
baseDirectory.value / "src-jvm", | ||
baseDirectory.value / "src-jvm-native", | ||
), | ||
(unmanagedSourceDirectories in Test) := Seq( | ||
baseDirectory.value / "test/src", | ||
baseDirectory.value / "test/src-jvm", | ||
baseDirectory.value / "test/src-jvm-native", | ||
), | ||
(unmanagedResourceDirectories in Test) := Seq( | ||
baseDirectory.value / "test/resources", | ||
), | ||
(sourceGenerators in Compile) += Def.task { | ||
val file = (Compile / sourceManaged).value / "jsonnet" / "Version.scala" | ||
IO.write(file, | ||
s"""package sjsonnet | ||
|object Version{ | ||
| val version = "${sjsonnetVersion}" | ||
|} | ||
|""".stripMargin) | ||
Seq(file) | ||
}.taskValue | ||
) | ||
|
||
lazy val bench = (project in file("bench")) | ||
.dependsOn(main) | ||
.enablePlugins(JmhPlugin) | ||
.settings( | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.3.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.7") | ||
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package java.util | ||
|
||
import java.util.stream.IntStream | ||
|
||
import scala.collection.mutable.{BitSet => SBitSet} | ||
import scala.collection.JavaConverters._ | ||
|
||
class BitSet(_initialSizeDummy: Int) extends java.lang.Cloneable { | ||
val bs: SBitSet = SBitSet.empty | ||
def isEmpty: Boolean = bs.isEmpty | ||
override def clone(): AnyRef = super.clone() | ||
def cardinality(): Int = bs.size | ||
def stream(): IntStream = IntStream.of(bs.toArray: _*) | ||
def get(i: Int): Boolean = bs.apply(i) | ||
def set(i: Int): Unit = bs += i | ||
def clear(): Unit = bs.clear() | ||
def andNot(other: BitSet): Unit = bs.&~=(other.bs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sjsonnet | ||
|
||
import java.util.BitSet | ||
|
||
object BitSetUtils { | ||
def iterator(bs: BitSet): Iterator[Int] = bs.bs.iterator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package sjsonnet | ||
|
||
import java.util.BitSet | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
object BitSetUtils { | ||
def iterator(bs: BitSet): Iterator[Int] = { | ||
val b = ArrayBuffer.empty[Int] | ||
var i = bs.nextSetBit(0) | ||
while(i > 0) { | ||
b += i | ||
i = bs.nextSetBit(i+1) | ||
} | ||
b.iterator | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package java.util | ||
|
||
import java.util.stream.IntStream | ||
|
||
import scala.collection.mutable.{BitSet => SBitSet} | ||
import scala.collection.JavaConverters._ | ||
|
||
class BitSet(_initialSizeDummy: Int) extends java.lang.Cloneable { | ||
val bs: SBitSet = SBitSet.empty | ||
def isEmpty: Boolean = bs.isEmpty | ||
override def clone(): AnyRef = super.clone() | ||
def cardinality(): Int = bs.size | ||
def stream(): IntStream = IntStream.of(bs.toArray: _*) | ||
def get(i: Int): Boolean = bs.apply(i) | ||
def set(i: Int): Unit = bs += i | ||
def clear(): Unit = bs.clear() | ||
def andNot(other: BitSet): Unit = bs.&~=(other.bs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sjsonnet | ||
|
||
import java.util.BitSet | ||
|
||
object BitSetUtils { | ||
def iterator(bs: BitSet): Iterator[Int] = bs.bs.iterator | ||
} |
Oops, something went wrong.