tronprotocol / tips

TRON Improvement Proposals
229 stars 203 forks source link

Proposal: Enable account asset optimization #473

Closed xxo1shine closed 1 year ago

xxo1shine commented 1 year ago

Simple Summary

Remove assets from account data structure and store them separately to improve system performance. For more details, please refer to: TIP-382.

Motivation

In the process of executing the transaction, most of the time is spent in the deserialization operation of the account. It is caused by the account asset list being too large. Some accounts have thousands of assets. During the deserialization process, it takes a lot of time.

In order to improve the performance of the blockchain, increase the TPS, it is necessary to reduce the transaction execution time, so it is necessary to optimize the data structure of account assets.

Timeline

Any opinions or discussions about this proposal are welcomed in the next two weeks.

The estimated timeline

Hi @TronSpark @fbsobreira, would you please help to raise a proposal to activate it. Thanks a lot.

How to Initialize the Voting Request

Background

According to the latest online statistics, there are currently 79,185,490 accounts and 6,595 assets. The statistics of the number of account assets are as follows.

range of assets number of accounts
> 1000 2
500 ~ 1000 51
200 ~ 500 1910
100 ~ 200 13219
50 ~ 100 161214

Through the performance analysis of the flame graph, it can be seen that the deserialization of the account takes a lot of time. Randomly select a batch of accounts, and perform 10,000 deserialization of complete data and clear asset data respectively. The analysis results are as follows:

complete data clear asset data
total cost 340,123ms 29,575ms
average cost 69ms 6ms

It can be seen that the performance of the deserialization operation of the account data is improved by more than ten times after the assets are cleared.

Performance Test

Tested under 3 different pressure models and got the results of the performance test

Pressure Model 1

  1. 100% of the traffic is trc20 transfer transaction.
  2. From address has 50 tokens, to address is a random account on the main network.

Test Results:

Before opening proposal 66, packaged qps is 340/s
After opening proposal 66, packaged qps is 417/s
Performance improvement: 22.6%

Pressure Model 2

  1. 100% of the traffic is trc20 transfer transaction.
  2. From address has 200 tokens, to address is a random account on the main network.

Test Results:

Before opening proposal 66,, packaged qps is 226/s
After opening proposal 66, packaged qps is 398/s
Performance improvement: 76%

Pressure Model 3

  1. The traffic is mainnet transactions.

Test Results:

Before opening proposal 66,, packaged qps is 370/s
After opening proposal 66, packaged qps is 484/s
Performance improvement: 30.8%
fbsobreira commented 1 year ago

The decoupling of assets in the account model will certainly be a big step forward for the Tron network which will make possible the processing of many more transactions by blocks in the time interval of 3s used by the validators on the network.

Let's push forward!

cryptoguyinza commented 1 year ago

A good enhancement. Happy to proceed 👍🏻

blmatthews commented 1 year ago

Seems like a good enhancement, but I'm curious if it will have any affect on the trongrid or tron web APIs? I use both extensively, so would just like to know if I'll have to make some changes to my code (which is fine).

xxo1shine commented 1 year ago

Seems like a good enhancement, but I'm curious if it will have any affect on the trongrid or tron web APIs? I use both extensively, so would just like to know if I'll have to make some changes to my code (which is fine).

Compatibility processing has been done and will not affect any api interface.

LauraYH commented 1 year ago

If the data availability is assured, why not? It possesses considerable system performance now for the assets tx. This definitely would help. Need more detail about the new structure that the assets data goes to.

TronSpark commented 1 year ago

All the data provided shows that this is a step in the right direction. Have any negative consequences been observed?

ethan1844 commented 1 year ago

Thanks to everyone's contribution to this proposal. This issue will be closed as it is already going to effect, check detail at: https://tronscan.org/#/proposal/74