cadence icon indicating copy to clipboard operation
cadence copied to clipboard

Investigate loaded value iterator for values loaded from storage

Open SupunS opened this issue 2 years ago • 1 comments

Current Behavior

As mentioned in the https://github.com/onflow/cadence/pull/2460#issuecomment-1670479115, when a resource array is loaded from storage, all elements seem to be also 'loaded' every time.

Expected Behavior

It should not load the elements, unless elements are accessed explicitly.

Steps To Reproduce

Debug the IterateLoaded when running BenchmarkRuntimeResourceTracking test case.

Environment

- Cadence version: Stable cadence

SupunS avatar Aug 09 '23 20:08 SupunS

@SupunS

On a side note, I noticed that when the resource array is loaded from storage, all elements seem to be also 'loaded' every time (so they get iterated every time, during resource tracking). Not sure if it is due to the mocked 'test ledger' we are using for unit tests, or the expected behavior. cc: @fxamacker

It seems BenchmarkRuntimeResourceTracking uses testLedger for storage. And testLedger uses local map for data storage and retrieval.

Is it possible this might be a reason for elements being loaded every time?

fxamacker avatar Aug 10 '23 15:08 fxamacker