Joel
Joel

Reputation: 23140

How can a Corda flow be written to minimise the size of checkpoints

Corda flows checkpoint before various operations. How can I write my flows to minimise checkpoint size and improve flow running time?

Upvotes: 0

Views: 58

Answers (1)

Joel
Joel

Reputation: 23140

You reduce checkpoint size by keeping the callstack minimal, as anything in scope in the execution stack will be serialized into the checkpoint.

One way to reduce the callstack is to factor out any operations that don't suspend into helper functions that are not marked as @Suspendable.

For example, suppose we write:

@Suspendable
fun asd() {
  val something = computeSomething()
  val somethingElse = lol(something)
  sendAndReceive(bla)
}

In this case, something and somethingElse will be in the checkpoint. So instead we should write:

@Suspendable
fun asd() {
  helper()
  sendAndReceive(bla)
}

fun helper() {
  val something = computeSomething()
  val somethingElse = lol(something)
}

And something and somethingElse will not be in the checkpoint.

Upvotes: 1

Related Questions