How We Solved RAM Consumption in EOS Rate

We’ve documented our experience improving RAM consumption in the open-source dApp EOS Rate that utilizes EOSIO blockchain technology on the EOS mainnet.

Before the Update

Critical Improvements

  1. EOS Rate was one of our first open-source projects when we started on the EOS blockchain back in September 2018. Later, we became aware that we misused the variable types ratings struct, which only stored values from 0 to 10; however, we incorrectly represented those values as float types. Even though it didn’t mean a significant improvement in RAM consumption, we believe that small changes can substantially impact it.
  2. Once we deployed the Eden implementation, we decided to scope all Eden and non-Eden members into one single scope — which we called rateproducer. We also added another more specific scope just for Eden members called eden. This way, Eden members will be able to add a record to the general rateproducer and eden scopes on the ratings and stats tables. Before this adjustment, Eden members had to pay double in bytes consumption compared to other EOS Rate users, meaning duplication of the value required.
  3. Secondary indexes require high use of RAM consumption with a total of 128 bytes per 64-bit integer key secondary index and double-precision floating-point key secondary index. Previously, on EOS Rate, there was a declared secondary index, but the smart contract logic didn’t yet use it.

During the Update

How RAM Consumption Works on EOSIO

  1. 64-bit integer key secondary index and the double-precision floating-point key secondary index: It may cause an additional 128 bytes of RAM to be billed per table row.
  2. 128-bit integer key secondary index and the quadruple-precision floating-point key secondary index: It may cause an additional 144 bytes of RAM to be billed per table row.
  3. 256-bit integer key secondary index: It causes an additional 160 bytes of RAM to be billed per table row.
  1. It has no row/s (full-emplace): When a user wants to add a new register to an existing Multi-Index table with no rows, the RAM payer needs to pay for extra RAM for the data serialization and the “table metadata” instance that has a static RAM cost of 112 bytes + table structure, which is another 112 bytes.
  2. It has row/s (emplace): It happens when there already exists at least a record on the table. In that case, a new emplace will pay only 112 bytes for “table metadata” + serialized struct.
  3. It has row/s (modify): When there already exists at least one record on the table, and a user wants to modify a specific record, the RAM payer may change. However, the RAM cost is going to be the same as first the emplace (emplace).

How RAM Consumption Worked on the rateproducer Smart Contract

After the Update

What We Did

  1. We separate the logic on our staging branch by querying it to the genesdeden account on Jungle 3 (which is an account that emulates the official Eden members table) and our master branch to genesis.eden account on Mainnet.
  2. We generated the abi file with its Ricardian Contract and Clauses from CLSDK.
  3. We removed the uniq_rating field from the new ratings_v2 struct. Instead of storing uniq_rating we now calculate it every time it is needed.
  4. We removed an unused secondary index by_user.
  5. We created a migration function to move data from the ratings to the rating table. At the same time, it will update the stats data on the rateproducer scope by removing eden member rates.
  6. We updated the table scopes. Now, Eden members will emplace only on the rating table under the eden scope. To calculate the non-eden and eden average, we need to apply the following formula:

Things We Will Do

Overall bytes improvements

--

--

EOS Block Producer candidate in the heart of the Americas. We stand for liberty and equality. Mainnet BP: costaricaeos · https://t.me/eoscr

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EOS Costa Rica

EOS Block Producer candidate in the heart of the Americas. We stand for liberty and equality. Mainnet BP: costaricaeos · https://t.me/eoscr