Scalacheck generator performance tips?

On my current project, we have a group of nested case classes that I am trying to instantiate from a JSON object.

  • Type A has some data plus an Option[List[B]]; mix of primitive types and compound types, with a total of 39 primitive fields in all.
  • Type B has some primitive data (partly optional) plus a List[C]; total of 8 fields
  • Type C has some primitive data (mostly optional) plus a List[D]; total of 21 fields
  • Type D has some data, total of 16 fields

I want to assert properties of a function that accepts an argument of type A. I would like to use property-based testing, but my Gen[A] type is extremely slow. It starts out fast, but as the generated lists become longer and longer, things slow to a crawl. It takes over 3 minutes to generate a hundred samples.

Has anyone built a fast generator for large-ish JSON-ey objects before? How did you do it?

Just to be clear, your problem is generating a sample of objects of type A, and there is no JSON involved in that step, right?

I suspect you are using a lot of heap memory and it spends a lot of time garbage collecting. You may try to increase heap space or use smaller lists on average, either by configuring the List generator or writing your own custom List generator.