Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tellnobody1 committed Jun 14, 2021
1 parent 90f7315 commit d2409eb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15.0
11
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# proto

[![version](https://img.shields.io/maven-central/v/io.github.zero-deps/proto_3.0.0-RC1?label=version)](https://repo1.maven.org/maven2/io/github/zero-deps/)
[![chat](https://img.shields.io/discord/786606353820942366)](https://discord.gg/ns7ZYssxZS)
[![version](https://img.shields.io/maven-central/v/io.github.zero-deps/proto_3?label=version)](https://repo1.maven.org/maven2/io/github/zero-deps/proto_3)
[![test](https://img.shields.io/github/workflow/status/zero-deps/proto/test?label=tests)](https://github.com/zero-deps/proto/actions/workflows/test.yml)
[![cloc](https://img.shields.io/badge/cloc-866-blue)](https://github.com/zero-deps/proto/tree/main/scala/src/main/scala-3.0.0-RC1)

Lightweight and fast serialization library for Scala 2/3 based on Protocol Buffers with macros magic.

Expand Down
86 changes: 43 additions & 43 deletions bench/src/main/scala-2.13/data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ object States {
val bytes: Array[Byte] = writeToArray(data)(codec)
}

@State(Scope.Benchmark)
class ProtobufState {
import com.google.protobuf.ByteString
val value = ByteString.copyFrom(Array.fill(1000)(1).map(_.toByte))
val lastModified: Long = 1552661477L
val vc = binarymodel.VectorClock(Vector.fill(2)(binarymodel.Version(node="169.0.0.1:4400", timestamp=2000L)))

val data = binarymodel.Data(value=value, lastModified=lastModified, vc=Some(vc))
val bytes: Array[Byte] = data.toByteArray
}
// @State(Scope.Benchmark)
// class ProtobufState {
// import com.google.protobuf.ByteString
// val value = ByteString.copyFrom(Array.fill(1000)(1).map(_.toByte))
// val lastModified: Long = 1552661477L
// val vc = binarymodel.VectorClock(Vector.fill(2)(binarymodel.Version(node="169.0.0.1:4400", timestamp=2000L)))

// val data = binarymodel.Data(value=value, lastModified=lastModified, vc=Some(vc))
// val bytes: Array[Byte] = data.toByteArray
// }

@State(Scope.Benchmark)
class MacrosState {
Expand Down Expand Up @@ -99,23 +99,23 @@ object States {
bb.get(bytes)
}

@State(Scope.Benchmark)
class KryoMacrosState {
val value = Array.fill(1000)(1).map(_.toByte)
val lastModified: Long = 1552661477L
val vc = VectorClock(Vector.fill(2)(Version(node="169.0.0.1:4400", timestamp=2000L)))

val data = Data(value=value, lastModified=lastModified, vc=vc)
import com.evolutiongaming.kryo.Serializer
val serializer = Serializer.make[Data]
import com.esotericsoftware.kryo.Kryo
val kryo = new Kryo
kryo.register(classOf[Data])
import com.esotericsoftware.kryo.io.Output
val output = new Output(1024, -1)
kryo.writeObject(output, data)
val bytes: Array[Byte] = output.getBuffer
}
// @State(Scope.Benchmark)
// class KryoMacrosState {
// val value = Array.fill(1000)(1).map(_.toByte)
// val lastModified: Long = 1552661477L
// val vc = VectorClock(Vector.fill(2)(Version(node="169.0.0.1:4400", timestamp=2000L)))

// val data = Data(value=value, lastModified=lastModified, vc=vc)
// import com.evolutiongaming.kryo.Serializer
// val serializer = Serializer.make[Data]
// import com.esotericsoftware.kryo.Kryo
// val kryo = new Kryo
// kryo.register(classOf[Data])
// import com.esotericsoftware.kryo.io.Output
// val output = new Output(1024, -1)
// kryo.writeObject(output, data)
// val bytes: Array[Byte] = output.getBuffer
// }
}

class Encode {
Expand All @@ -139,10 +139,10 @@ class Encode {
bh.consume(writeToArray(state.data)(state.codec))
}

@Benchmark
def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
bh.consume(state.data.toByteArray)
}
// @Benchmark
// def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
// bh.consume(state.data.toByteArray)
// }

@Benchmark
def proto(state: States.MacrosState, bh: Blackhole): Unit = {
Expand All @@ -158,14 +158,14 @@ class Encode {
bh.consume(bytes)
}

@Benchmark
def kryo_macros(state: States.KryoMacrosState, bh: Blackhole): Unit = {
import com.esotericsoftware.kryo.io.Output
val output = new Output(1024, -1)
state.kryo.writeObject(output, state.data)
val bytes: Array[Byte] = output.getBuffer
bh.consume(bytes)
}
// @Benchmark
// def kryo_macros(state: States.KryoMacrosState, bh: Blackhole): Unit = {
// import com.esotericsoftware.kryo.io.Output
// val output = new Output(1024, -1)
// state.kryo.writeObject(output, state.data)
// val bytes: Array[Byte] = output.getBuffer
// bh.consume(bytes)
// }
}

class Decode {
Expand All @@ -188,10 +188,10 @@ class Decode {
bh.consume(readFromArray(state.bytes)(state.codec): Data)
}

@Benchmark
def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
bh.consume(binarymodel.Data.parseFrom(state.bytes): binarymodel.Data)
}
// @Benchmark
// def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
// bh.consume(binarymodel.Data.parseFrom(state.bytes): binarymodel.Data)
// }

@Benchmark
def proto(state: States.MacrosState, bh: Blackhole): Unit = {
Expand Down
26 changes: 13 additions & 13 deletions bench/src/main/scala-2.13/msg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ object States {
val bytes: Array[Byte] = writeToArray(msg)(codec)
}

@State(Scope.Benchmark)
class ProtobufState {
val msg = binarymodel.Msg(Some(binarymodel.Stat("cpu", "0.45")), Some(binarymodel.StatMeta("1571067208996", "127.0.0.1:8080")))
val bytes: Array[Byte] = msg.toByteArray
}
// @State(Scope.Benchmark)
// class ProtobufState {
// val msg = binarymodel.Msg(Some(binarymodel.Stat("cpu", "0.45")), Some(binarymodel.StatMeta("1571067208996", "127.0.0.1:8080")))
// val bytes: Array[Byte] = msg.toByteArray
// }

@State(Scope.Benchmark)
class MacrosState {
Expand All @@ -42,10 +42,10 @@ class Encode {
bh.consume(writeToArray(state.msg)(state.codec))
}

@Benchmark
def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
bh.consume(state.msg.toByteArray)
}
// @Benchmark
// def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
// bh.consume(state.msg.toByteArray)
// }

@Benchmark
def protobuf_scala_macros(state: States.MacrosState, bh: Blackhole): Unit = {
Expand All @@ -60,10 +60,10 @@ class Decode {
bh.consume(readFromArray(state.bytes)(state.codec): Msg)
}

@Benchmark
def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
bh.consume(binarymodel.Msg.parseFrom(state.bytes): binarymodel.Msg)
}
// @Benchmark
// def scalapb(state: States.ProtobufState, bh: Blackhole): Unit = {
// bh.consume(binarymodel.Msg.parseFrom(state.bytes): binarymodel.Msg)
// }

@Benchmark
def protobuf_scala_macros(state: States.MacrosState, bh: Blackhole): Unit = {
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ThisBuild / crossScalaVersions := "3.0.0" :: "2.13.6" :: Nil
lazy val proto = project.in(file("proto")).settings(
name := "proto",
version := zero.git.version(),
libraryDependencies += "com.google.protobuf" % "protobuf-java" % "3.17.0"
libraryDependencies += "com.google.protobuf" % "protobuf-java" % "3.17.3"
).dependsOn(protoops)

lazy val protopurs = project.in(file("purs")).settings(
Expand Down Expand Up @@ -65,6 +65,7 @@ ThisBuild / licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
ThisBuild / versionScheme := Some("pvp")
ThisBuild / publishTo := Some(Opts.resolver.sonatypeStaging)
ThisBuild / credentials += Credentials("GnuPG Key ID", "gpg", "F68F0EADDB81EF533C4E8E3228C90422E5A0DB21", "ignored")
ThisBuild / isSnapshot := true

ThisBuild / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.5.2
sbt.version=1.5.4

0 comments on commit d2409eb

Please sign in to comment.