solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Solidity needs to support the trie type, so that the amount of stored data is smaller and the search is faster. The gas of contract transactions will be reduced

Open Marius-BC-Dev opened this issue 3 years ago • 6 comments

Marius-BC-Dev avatar Jul 29 '22 13:07 Marius-BC-Dev

Can you elaborate? What use cases do you have in mind?

This sounds like something that could be implemented as a third-party library. We're currently working on adding generics to the language, which should make implementing such libraries in a reusable way even easier. I think that's a better approach than making more data structures a core part of the language.

cameel avatar Jul 29 '22 16:07 cameel

I have considered using a third-party library to implement this function. In the way of a third-party library, the size of the stored data cannot be reduced.

Marius-BC-Dev avatar Jul 31 '22 12:07 Marius-BC-Dev

For example, use map to store account balance, and modify it to use trie structure type to store data will be better. Because it can reduce the gas consumption of contract state data storage.

Marius-BC-Dev avatar Aug 01 '22 08:08 Marius-BC-Dev

I don't really see why it would necessarily have to be more expensive when implemented as a separate data structure. Solidity might be missing some high-level syntax to do it nicely (then you should rather request those instead) but ultimately you can always implement things in inline assembly. Solidity ultimately generates assembly to handle maps too.

cameel avatar Aug 01 '22 11:08 cameel

I think you understand solidity's storage better than I do. In the map structure, each key uses a space for storage, etc. If the trie structure is used, the key can be partially shared, so the storage size and gas can be reduced.

Marius-BC-Dev avatar Aug 02 '22 01:08 Marius-BC-Dev

each key uses a space for storage

Not really. For mappings keys are not stored at all. That's why you cannot enumerate the elements or copy the whole mapping.

cameel avatar Aug 03 '22 09:08 cameel

This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.

github-actions[bot] avatar Mar 30 '23 12:03 github-actions[bot]

Hi everyone! This issue has been automatically closed due to inactivity. If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen. However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.

github-actions[bot] avatar Apr 08 '23 12:04 github-actions[bot]