EspressoSystems / hotshot-query-service

Generic query service for HotShot applications
https://espressosystems.github.io/hotshot-query-service/
GNU General Public License v3.0
5 stars 1 forks source link

Improve efficiency of aggregated statistics #735

Closed jbearer closed 1 week ago

jbearer commented 1 week ago

We have some statistics that are derived from the entire block history, namely transaction count and payload size. Previously, these were computed on the fly each request, which requires an expensive full table scan and, in the case of payload size, a large sum. We saw this causing performance problems on decaf and mainnet, particularly the block explorer, which uses these statistics heavily

This PR:

Adds a new table aggregate, which stores these cumulative values at each block height. This table is kept up to date by a background task scanning the block stream. Now, looking up the values of these statistics just requires reading a single row in this table. This approach has numerous benefits in addition to a massive performance improvement: