-
-
Notifications
You must be signed in to change notification settings - Fork 142
readValue for Map[String, Any] or List[Any] is very slow #145
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
Comments
10x seems unreasonable to have to work around, but I'll have to do some benchmarking to find what's causing it. Do you find the same slowdown with |
It works great with |
Ok, thanks; I will investigate and see what can be done. |
I have some stats and a simple benchmarking script to share: https://gist.github.com/anantn/87a7a696b9059979189d - 100 iterations over a 800-line json file.
|
I have the same problem. def deser(value: String): Map[String, Any] = {
mapper.readValue(value, classOf[Map[String, Any]])
} On a 31MB file with 270560 jsons, it takes 191 secs. On the same machine |
Not sure if it'd help but there are at least 2 possible sources of problem:
To work around first one, you may be able to pre-resolve
and then pass For second part (and actually also solving first one, if it was an issue) you can pre-construct
which will resolve type, and pre-fetch serializer needed for that type. I don't know if this works around the performance issue, but it is worth trying, until root cause is found. |
I'm circumventing this by manually converting Java collections into Scala types recursively: def convert(obj: Any): Any = {
import collection.JavaConverters._
obj match {
case l: java.util.List[_] => l.asScala.map{convert}.toList
case m: java.util.Map[_, _] => m.asScala.mapValues(convert).view.force
case _ => obj
}
}
val mapper = new ObjectMapper
convert(mapper.readValue(json, classOf[java.util.Map[String, _]])) That gives me a |
@anantn, can you share your 800-line test file? I have my own test data to run with, but I will be better able to reproduce your issue if I can profile the same data. Feel free to contact me privately if you don't want the data to be public. |
@christophercurrie Sure, here you go: https://gist.github.com/anantn/0899635c42ee8d72eed2 |
Some work has been done on this issue in the 2.4 branch, which I need to release in the next few days; if any of you have the chance to run your local perf tests on 2.4.4-SNAPSHOT, your feedback would be appreciated. |
FYI, version 2.4.4 was released today. Hopefully it will improve things for you. |
Closing this issue as resolved; reports have come in on a similar issue that performance has improved in 2.4.4. If this is not your experience, feel free to open a new issue. |
Anytime there's a type that contains 'Any', 'AnyRef' or '_', the scala module's performance is very slow.
Consider JSON of the form
["foo", "bar", "baz"]
.objectMapper.readValue[List[_]](json)
is 10x slower thanobjectMapper.readValue[List[String]](json)
.This would be fine on its own, except in the cases where the JSON contains mixed types. What would be the optimal way to parse JSON that looks like the following?
The text was updated successfully, but these errors were encountered: