uuosio / ascdk

MIT License
12 stars 9 forks source link

Utility to estimate RAM #67

Open jafri opened 2 years ago

jafri commented 2 years ago

Would be interesting to be able to estimate on-chain RAM bytes size from Packer+Table

learnforpractice commented 2 years ago

The following code may help measuring ram usage:

test_account = 'hello'
args = {
    'payer': test_account,
    'receiver': test_account,
    'bytes': 1024*1024*2,
}
chain.push_action('eosio', 'buyrambytes', args, {test_account: 'active'})

info = chain.api.get_account('hello')
before = info['ram_usage']

args = dict()
r = chain.push_action('hello', 'testmi2', args, {'hello': 'active'})

info = chain.api.get_account('hello')
after = info['ram_usage']
logger.error('ram usage by action: %s', after - before)
jafri commented 2 years ago

Right, I mean measuring how much RAM a table row would take inside the contract itself, to automatically buy that much RAM

learnforpractice commented 2 years ago

The ram costs by store a value in a table the first time is much more than other times.

So it need a test I think.

jafri commented 2 years ago

The first time extra cost is because of the scope creation I believe