tip-290.md

April 3, 2025 · View on GitHub

tip: 290
title: Dynamic store optimization
author: lucas.wu@tron.network
discussions to: https://github.com/tronprotocol/TIPs/issues/290
status: Final
category: Core
created: 2021-07-12

Simple Summary

This TIP is to optimize dynamic store query performance.

Abstract

Through analysis, a lot of time is spent on dynamic store queries during block processing.

A total of 304 blocks were counted, including 36044 transactions, the number of dynamic store queries reached 1119525, and the number of queries hitting the cache was 340416. It can be analyzed through the statistical results that, on average, each transaction requires 1119525/36044 = 31 dynamic store queries, and two-thirds of the queries cannot hit the cache, that is, 20 dynamic store queries for each transaction cannot hit the cache.

In block synchronization, the cost of failing to hit the cache is very high. In the block synchronization logic, after 500 blocks are synchronized, the flash operation will be performed. Before flashing, each block will produce one session (cache). The query logic starts from the outermost cache. If the key is not in the cache, each query needs to be traversed 500 times and then retrieved from the DB.

This article describes the query optimization of the dynamic store.

Motivation

In order to reduce block processing time, improve the performance of the blockchain, increase the TPS, it is necessary to optimize dynamic store query performance.

Implementation

Due to the particularity of the dynamic store, the key of the entire database is limited. You can consider loading all the data of the dynamic store into the first-level cache, so that the performance will rise sharply.

Performance Testing:

block count: 8000, transaction count:903262

Before optimization:

dynamic store query timescache hitscache hit probability
26588491858225932.28%

After optimization:

dynamic store query timescache hitscache hit probability
265884912658823299.999%


Time-consuming comparison of block processing:

Before optimization: total costBefore optimization: average costAfter optimization: total costAfter optimization: average cost
14766361841085780135
13997911741066748133

Before optimization average cost: 179, After optimization average cost: 134 Performance improvement: (179 - 134) / 134 = 33.58%

Copyright and related rights waived via CC0.