Is Play JSON smart enough to pre-allocate an IndexedSeq when given a JsArray?


#1

I use Format on my case classes to convert to/from JSON. When dealing with an array of something in the JSON, I’ve always used Seq[...] in the case-class. Due to a performance issue in an unrelated part of my code, I find myself needing to switch from Seq, which gives you a List by default, to IndexedSeq (which gives a Vector) - I am handing off objects with a large sequence (tens of thousands of elements) to a Java library which calls size() repeatedly (Java collections have an O(1) size()… whereas Scala collections like List actually behave like they’re supposed to and have an O(n) size()). My question is - when converting a given JsArray into a case class which has an IndexedSeq, will the converter be smart enough to pre-allocate the IndexedSeq to the length of the elements in the JsArray?

case class Foo(things: Seq[Bar])

object Foo {
  implicit val format = Json.format[Foo]
}```

#2

Anyone? Thanks.