mercredi 21 novembre 2018

Spock performance problems

I've some problems with performance with specifications implemented in spock - I mean execution time in particular. After digging into the problem I've noticed that it's somehow related with setting spec up - I don't mean setup() method in particular. After this discovery I added @Shared annotation to all the fields declared in the specification and it runs 2 times faster than before. Then I thought that performance problems may be related with ConcurrentHashMap or random* methods (from commons-lang3) but that wasn't the case. Then in an act of desperation I decorated all the fields in my specification in the following way:

class EntryFacadeSpec extends Specification {

  static {
    println(System.currentTimeMillis())
  }
  @Shared
  def o = new Object()
  static {
    println(System.currentTimeMillis())
  }
  @Shared
  private salesEntries = new InMemorySalesEntryRepository()
  static {
    println(System.currentTimeMillis())
  }
  @Shared
  private purchaseEntries = new InMemoryPurchaseEntryRepository()
  static { 
    println(System.currentTimeMillis())
  }

  ...

What's interesting, no matter which field is declared as the first it takes hundreds of milliseconds to initialize the field:

1542801494583
1542801495045
1542801495045
1542801495045
1542801495045
1542801495045
1542801495045
1542801495045
1542801495045
1542801495045
1542801495046
1542801495046
1542801495046
1542801495046
1542801495047
1542801495047

What's the problem? How to save this several hundred milliseconds?

Aucun commentaire:

Enregistrer un commentaire