cadence
                                
                                
                                
                                    cadence copied to clipboard
                            
                            
                            
                        Investigate loaded value iterator for values loaded from storage
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
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?