rusk-vm
rusk-vm copied to clipboard
VM2 Investigate Contract Code Size
Describe what you want implemented In VM2 contract size grew in comparison with VM1. Gather more data for proper comparison and try to explain what is causing the growth.
Describe "Why" this is needed We need it to be able to influence and control bytecode sizes for VM2.
Describe alternatives you've considered There is really no alternative.
Additional context Until now we focused on gas usage measurements, but code size is also important.
At the time of writing - https://github.com/dusk-network/rusk-vm/commit/e2fa3209589303c246b14f9cb5ce571de55f266a - here is a comparison test contract sizes. The first column is the size with the code unaltered, while the second is the code with the following modifications:
-
Removing
std
dependency ofmap
,stack
, andstring_argument
contracts. -
Introducing the following language items in
rusk-uplink
:-
alloc_error_handler
-
panic_handler
-
wee_alloc
asglobal_allocator
-
Test contract | VM1 | VM1 with build opts | VM2 | VM2 with mods | VM2 with mods and build opts |
---|---|---|---|---|---|
block_height | 13K | 5K | 27K | 18K | 11K |
callee_1 | 23K | 16K | 45K | 37K | 24K |
callee_2 | 19K | 12K | 40K | 31K | 19K |
caller | 20K | 12K | 45K | 36K | 23K |
counter | 17K | 9K | 34K | 25K | 17K |
delegator | 19K | 11K | 32K | 24K | 15K |
events | N/A | N/A | 30K | 22K | 14K |
fibonacci | 16K | 7K | 30K | 21K | 13K |
gas_consumed | 15K | 7K | 30K | 22K | 14K |
gas_context | 22K | 14K | 50K | 42K | 26K |
map | 37K | 28K | 66K | 57K | 44K |
minimal_counter | N/A | N/A | 28K | 20K | 12K |
register | N/A | N/A | 71K | 63K | 48K |
self_snapshot | 25K | 19K | 38K | 30K | 22K |
stack | 39K | 30K | 73K | 65K | 49K |
string_argument | N/A | N/A | 28K | 20K | 12K |
tx_vec | 20K | 12K | 49K | 40K | 18K |
As one can see the sizes are still significantly larger - sometimes double. The experiment can be found in the size-reduction-374 branch.
EDIT: the last column adds some build optimization options to the contracts, and makes them much smaller. It does make some tests fail - specifically the ones using the stack contract.
EDIT: added another column adding the same optimization options to VM1. As expected, sizes are significantly smaller as in VM2. Some tests fail here too - specifically panicking_nested
and self_snapshot
. Experiment in the size-reduction-vm1-374
branch.
VM1 vs VM2 gas usage comparison results: (VM1 test run on 06 May 2022)
Test | VM1 | VM2 | VM2 with mods |
---|---|---|---|
counter | 5,493 | 9,564 | 9,532 |
stack single push/pop | 31,937 | 13,426 | 13,726 |
stack multiple push/pop (65536) | 806,802,898 | 255,004,445 | 254,352,221 |
stack multiple transactions push (8192) | 1,290,562,425 | 221,023,128 | 230,148,192 |
hamt single insert/get | 41,472 | 19,860 | 20,492 |
hamt multiple insert/get (8192) | 1,606,679,210 | 161,104,066 | 166,281,410 |
the same tests with refreshed VM1 data: (run on 23 June 2022)
Test | VM1 | VM2 | VM2 with mods |
---|---|---|---|
counter | 5,426 | 9,564 | 9,532 |
stack single push/pop | 19,015 | 13,426 | 13,726 |
stack multiple push/pop (65536) | 594,745,327 | 255,004,445 | 254,352,221 |
stack multiple transactions push (8192) | 791,263,208 | 221,023,128 | 230,148,192 |
hamt single insert/get | 25,088 | 19,860 | 20,492 |
hamt multiple insert/get (8192) | 1,048,506,722 | 161,104,066 | 166,281,410 |
tested VM1 code is in branch master-vm1-gas-usage 1ebdc25162
tested VM2 code is in branch master e2fa320958
tested VM2 with mods code is in branch size-reduction-374 dd1ec63887
Bench run comparison between VM1 and VM2:
Bench | VM1 | VM2 |
---|---|---|
Fibonacci 15 | 165.51 ms | 211.29 ms |
Stack 64 | 6.734 ms | 8.889 ms |