Skip to content

Commit

Permalink
remove msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Zoller committed May 21, 2024
1 parent 3d41c1a commit 0823f7d
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 893 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ ScalaJack 8 is an all-new ScalaJack serializer implemenation built on Scala 3. F
using Scala 3.4.1 on JDK 21 LTS version.

ScalaJack is a very fast, seamless serialization engine for unstructured data types designed to require a bare minimum of extra code
to serialize a class. ScalaJack supports JSON and MsgPack as part of its focus on over-the-wire data and message/event transport.
to serialize a class. ScalaJack supports JSON in its focus on over-the-wire data and message/event transport. (We looked at offering MsgPack support, but to our surprise benchmarks
showed that MsgPack serialization had about 25% slower write performance and 45% slower read performance than JSON, so for now we're sticking with just JSON support.)

Advanced Features:

Expand Down
8 changes: 4 additions & 4 deletions benchmark/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val compilerOptions = Seq(

val circeVersion = "0.15.0-M1"
val scalaTestVersion = "3.2.11"
ThisBuild / scalaVersion := "3.3.0"
ThisBuild / scalaVersion := "3.4.1"

def priorTo2_13(scalaVersion: String): Boolean =
CrossVersion.partialVersion(scalaVersion) match {
Expand All @@ -37,14 +37,14 @@ lazy val benchmark = project
libraryDependencies ++= Seq(
"org.playframework" %% "play-json" % "3.0.1",
"io.argonaut" %% "argonaut" % "6.3.9",
"co.blocke" %% "scalajack" % "efad12_unknown",
"co.blocke" %% "scalajack" % "8.0.0",
"dev.zio" %% "zio-json" % "0.6.1",
"org.typelevel" %% "fabric-core" % "1.12.6",
"org.typelevel" %% "fabric-io" % "1.12.6",
"org.typelevel" %% "jawn-parser" % "1.3.2",
"org.typelevel" %% "jawn-ast" % "1.3.2",
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.24.5-SNAPSHOT",
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.24.5-SNAPSHOT" % "compile-internal",
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.28.5",
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.28.5" % "compile-internal",
// "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.24.4",
// "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.24.4" % "compile-internal",
// "io.circe" %% "circe-derivation" % "0.15.0-M1",
Expand Down
17 changes: 1 addition & 16 deletions benchmark/src/main/scala/co.blocke/Benchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ trait HandTooledWritingBenchmark {
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
class ReadingBenchmark
// extends MsgPack.MsgPackReadingBenchmark
extends ScalaJackZ.ScalaJackReadingBenchmark
// with CirceZ.CirceReadingBenchmark
// extends JsoniterZ.JsoniterReadingBenchmark
Expand All @@ -55,25 +54,11 @@ class ReadingBenchmark
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
class WritingBenchmark
// extends MsgPack.MsgPackWritingBenchmark
// extends HandTooledWritingBenchmark
// extends CirceZ.CirceWritingBenchmark
// extends ScalaJackZ.MsgPackWritingBenchmark
extends ScalaJackZ.ScalaJackWritingBenchmark
// extends JsoniterZ.JsoniterWritingBenchmark
// with ZIOZ.ZIOJsonWritingBenchmark
// with PlayZ.PlayWritingBenchmark
// with ArgonautZ.ArgonautWritingBenchmark



/* LATEST RUN:
[info] Benchmark Mode Cnt Score Error Units
[info] ReadingBenchmark.readRecordJsoniter thrpt 20 1346388.345 ± 17028.863 ops/s
[info] ReadingBenchmark.readRecordScalaJack thrpt 20 941679.824 ± 58208.523 ops/s
[info] ReadingBenchmark.readRecordZIOJson thrpt 20 590995.917 ± 817.817 ops/s
[info] ReadingBenchmark.readRecordCirce thrpt 20 210805.946 ± 32488.564 ops/s
[info] ReadingBenchmark.readRecordPlay thrpt 20 198747.067 ± 7253.896 ops/s
[info] ReadingBenchmark.readRecordArgonaut thrpt 20 183670.032 ± 8981.485 ops/s
*/
19 changes: 0 additions & 19 deletions benchmark/src/main/scala/co.blocke/MsgPack.scalax

This file was deleted.

12 changes: 0 additions & 12 deletions benchmark/src/main/scala/co.blocke/ScalaJack.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ object ScalaJackZ:

given sj: ScalaJack[co.blocke.Record2] = sjCodecOf[co.blocke.Record2]

// implicit val blah: ScalaJack[co.blocke.Record2] = sjCodecOf[co.blocke.Record2]

trait ScalaJackReadingBenchmark{
@Benchmark
def readRecordScalaJack = sj.fromJson(jsData2)
Expand All @@ -20,16 +18,6 @@ object ScalaJackZ:
def writeRecordScalaJack = sj.toJson(record)
}

trait MsgPackReadingBenchmark{
@Benchmark
def readRecordScalaJack = sj.fromMsgPack(jsData2)
}

trait MsgPackWritingBenchmark {
@Benchmark
def writeRecordScalaJack = sj.toMsgPack(record)
}

/*
This is the way:
Expand Down
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ lazy val root = project
"co.blocke" %% "scala-reflection" % "2.0.6",
"org.apache.commons" % "commons-text" % "1.11.0",
"io.github.kitlangton" %% "neotype" % "0.0.9",
"org.msgpack" % "msgpack-core" % "0.9.8",
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"org.json4s" %% "json4s-core" % "4.0.6" % Test,
"org.json4s" %% "json4s-native" % "4.0.6" % Test
Expand Down
21 changes: 3 additions & 18 deletions src/main/scala/co.blocke.scalajack/ScalaJack.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import scala.quoted.*

import quoted.Quotes
import json.*
import msgpack.*

case class ScalaJack[T](jsonCodec: JsonCodec[T], msgPackCodec: MsgPackCodec[T]): // extends JsonCodec[T] //with YamlCodec with MsgPackCodec
case class ScalaJack[T](jsonCodec: JsonCodec[T]):
def fromJson(js: String): T =
jsonCodec.decodeValue(reading.JsonSource(js))

Expand All @@ -17,18 +16,6 @@ case class ScalaJack[T](jsonCodec: JsonCodec[T], msgPackCodec: MsgPackCodec[T]):
jsonCodec.encodeValue(a, out.clear())
out.result

val outArray = new org.msgpack.core.buffer.ArrayBufferOutput()
def toMsgPack(a: T): Array[Byte] =
outArray.clear()
val outMP = org.msgpack.core.MessagePack.newDefaultPacker(outArray)
msgPackCodec.encodeValue(a, outMP)
outMP.close()
outArray.toByteArray

def fromMsgPack(a: Array[Byte]): T =
val inMP = org.msgpack.core.MessagePack.newDefaultUnpacker(a)
msgPackCodec.decodeValue(inMP)

// ---------------------------------------

object ScalaJack:
Expand All @@ -41,9 +28,8 @@ object ScalaJack:
import quotes.reflect.*
val classRef = ReflectOnType[T](quotes)(TypeRepr.of[T], true)(using scala.collection.mutable.Map.empty[TypedName, Boolean])
val jsonCodec = JsonCodecMaker.generateCodecFor(classRef, SJConfig)
val mpCodec = MsgPackCodecMaker.generateCodecFor(classRef, SJConfig)

'{ ScalaJack($jsonCodec, $mpCodec) }
'{ ScalaJack($jsonCodec) }

// ----- Use given JsonConfig
inline def sjCodecOf[T](inline cfg: SJConfig): ScalaJack[T] = ${ codecOfImplWithConfig[T]('cfg) }
Expand All @@ -52,5 +38,4 @@ object ScalaJack:
val cfg = summon[FromExpr[SJConfig]].unapply(cfgE)
val classRef = ReflectOnType[T](quotes)(TypeRepr.of[T], true)(using scala.collection.mutable.Map.empty[TypedName, Boolean])
val jsonCodec = JsonCodecMaker.generateCodecFor(classRef, cfg.getOrElse(SJConfig))
val mpCodec = MsgPackCodecMaker.generateCodecFor(classRef, SJConfig)
'{ ScalaJack($jsonCodec, $mpCodec) }
'{ ScalaJack($jsonCodec) }
9 changes: 0 additions & 9 deletions src/main/scala/co.blocke.scalajack/msgpack/MsgPackCodec.scala

This file was deleted.

Loading

0 comments on commit 0823f7d

Please sign in to comment.