0

I defined an array of objects in the Ethereum smart contract. An object is a structure that is inserted into the array every time a function is called.When 80,000 data is inserted, it takes a long time, estimated at 25 hours...When traversing the array filter, directly reported timeout.The geth client used enter image description here enter image description here

1

The EVM is ineffective for working with large arrays. Use mapping. Design your contract to avoid iterative processing of large arrays

2
  • Since I am doing an analysis and research on the performance of block chain storage and query of large amount of data, I need to use a set to store data. Due to the data format, I may not be able to construct the mapping
    – myl
    Jan 6 at 10:52
  • Perhaps you will be interested in an article on comparing the use of an array and mapping in smart contracts (in Russian) -habr.com/ru/company/raiffeisenbank/blog/354122
    – Mad Jackal
    Jan 6 at 15:29
1

I find it very unnecessary to use an array and traverse over it.If you really want to do something like this, just don't use loop

Question 1: Why don't use loops?

Answer: Because Transaction fee will increase with each loop and will cost use alot of money. Plus it's the slowest method for searching method

Question 2: Then what is other option to do code this function?

Answer: Store each id in mapping(address=>uint256[]). It will cost you alot less and it'll be far more efficient also.

1
  • Since I am doing an analysis and research on the performance of block chain storage and query of large amount of data, I need to use a set to store data. Due to the data format, I may not be able to construct the mapping
    – myl
    Jan 6 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.