【发布时间】:2017-06-03 11:50:31
【问题描述】:
为什么 Circe Json 使用隐式解码器查找比将隐式解码器保存到 val 时更慢。
我希望这些是相同的,因为隐式解析是在运行时完成的。
import io.circe._
import io.circe.generic.auto._
import io.circe.jackson
import io.circe.syntax._
private val decoder = implicitly[Decoder[Data.Type]]
def decode(): Either[Error, Type] = {
jackson.decode[Data.Type](Data.json)(decoder)
}
def decodeAuto(): Either[Error, Type] = {
jackson.decode[Data.Type](Data.json)
}
[info] DecodeTest.circeJackson thrpt 200 69157.472 ± 283.285 ops/s
[info] DecodeTest.circeJacksonAuto thrpt 200 67946.734 ± 315.876 ops/s
完整的 repo 可以在这里找到。 https://github.com/stephennancekivell/some-jmh-json-benchmarks-circe-jackson
【问题讨论】:
-
Scala 在运行时从不解析隐式