cya icon indicating copy to clipboard operation
cya copied to clipboard

Scheduled Txs: Optimise transaction scheduler process

Open devbugging opened this issue 5 months ago • 4 comments

We should optimise the check that is always performed at the begining of process() function to not check the first item in the array, but instead hold the first item in array cached in a variable. This way the loading of array from storage is avoided thus reducing the execution effort used. https://github.com/onflow/flow-core-contracts/blob/master/contracts/FlowTransactionScheduler.cdc#L483

devbugging avatar Sep 24 '25 12:09 devbugging

That might not be easy to do because we can't add fields in upgrades.

joshuahannan avatar Sep 24 '25 14:09 joshuahannan

@devbugging Can you elaborate on what the issue is? Or have we already addressed it? The code looks like it changed, so the line you link to isn't really relevant any more.

joshuahannan avatar Dec 01 '25 20:12 joshuahannan

I was thinking of caching the first element in the array in a seperate variable so we don't access a big array, but I'm not sure how much of a performance impact that is in Cadence. https://github.com/onflow/flow-core-contracts/blob/master/contracts/FlowTransactionScheduler.cdc#L517

devbugging avatar Dec 09 '25 14:12 devbugging

I don't believe that accessing a single array element is very costly, even if the array is large. I think that copying a large array or iterating through a large array are what is costly. @onflow/cadence Can you confirm?

Also, in order to track that, we would have to use account storage and copy it from storage every time we checked there, which is probably also costly

joshuahannan avatar Dec 09 '25 18:12 joshuahannan