Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor Jackson code to hardcode buffer-recycler #999

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def specs2(scalaVersion: String) =
("org.specs2" %% s"specs2-$n" % "4.20.5") % Test
}

val jacksonDatabindVersion = "2.14.3"
val jacksonDatabindVersion = "2.16.2"
val jacksonDatabind = Seq(
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonDatabindVersion
)

val jacksonVersion = "2.14.3"
val jacksonVersion = "2.16.2"
val jacksons = Seq(
"com.fasterxml.jackson.core" % "jackson-core",
"com.fasterxml.jackson.core" % "jackson-annotations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ListBuffer

import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.core.JsonFactoryBuilder
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.JsonTokenId
import com.fasterxml.jackson.core.StreamReadConstraints
import com.fasterxml.jackson.core.Version
import com.fasterxml.jackson.core.json.JsonWriteFeature
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
import com.fasterxml.jackson.core.util.JsonRecyclerPools

import com.fasterxml.jackson.databind.Module.SetupContext
import com.fasterxml.jackson.databind._
Expand Down Expand Up @@ -282,9 +285,17 @@ private[json] object JacksonJson {
}

private[json] case class JacksonJson(jsonConfig: JsonConfig) {
private val mapper = (new ObjectMapper).registerModule(new PlayJsonMapperModule(jsonConfig))

private val jsonFactory = new JsonFactory(mapper)
private val streamReadConstraints = StreamReadConstraints
.builder()
.maxNumberLength(Integer.MAX_VALUE)
.build()
private val jsonFactory = JsonFactory
.builder()
.asInstanceOf[JsonFactoryBuilder]
.streamReadConstraints(streamReadConstraints)
.recyclerPool(JsonRecyclerPools.threadLocalPool())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jackson 2.17.0 used a very inefficient recycler pool that behaved even worse under heavy load - called 'Lock Free'. Jackson 2.17.1 and 2.17.2 (just released) goes back to ThreadLocalPool as the default. Still maybe a good idea to hardcode its use though.

.build()
private val mapper = new ObjectMapper(jsonFactory).registerModule(new PlayJsonMapperModule(jsonConfig))

private def stringJsonGenerator(out: java.io.StringWriter) =
jsonFactory.createGenerator(out)
Expand Down
Loading