Skip to content

Commit 4e16bed

Browse files
authored
Improve Contract Call by not encoding fuelvm protocol args (#7447)
## Description This is an optimization of contract calls on top of #7440. ```csv const_of_contract_call::cost_of_in_array_0,1976,1285 const_of_contract_call::cost_of_in_array_1,3164,1779 const_of_contract_call::cost_of_in_array_16,5096,4753 const_of_contract_call::cost_of_in_array_32,8421,8079 const_of_contract_call::cost_of_in_array_64,60382,14545 const_of_contract_call::cost_of_in_array_8,4724,4382 const_of_contract_call::cost_of_in_b256,2491,2147 const_of_contract_call::cost_of_in_bool,2627,2279 const_of_contract_call::cost_of_in_str_0,3043,2697 const_of_contract_call::cost_of_in_str_1,3345,2998 const_of_contract_call::cost_of_in_str_16,3374,3030 const_of_contract_call::cost_of_in_str_32,3572,3227 const_of_contract_call::cost_of_in_str_8,3768,3421 const_of_contract_call::cost_of_in_tuple_0,3822,3479 const_of_contract_call::cost_of_in_tuple_1,4392,4050 const_of_contract_call::cost_of_in_tuple_2,4761,4418 const_of_contract_call::cost_of_in_tuple_3,5104,4761 const_of_contract_call::cost_of_in_tuple_4,5468,5126 const_of_contract_call::cost_of_in_u16,4493,4141 const_of_contract_call::cost_of_in_u256,4777,4433 const_of_contract_call::cost_of_in_u32,4926,4582 const_of_contract_call::cost_of_in_u64,4934,4589 const_of_contract_call::cost_of_in_u8,4874,4526 const_of_contract_call::in_enum_u64,3186,2843 const_of_contract_call::in_enum_u64_u64,3061,2718 const_of_contract_call::in_enum_u64_u64_u64,3173,2830 const_of_contract_call::in_struct_u64,3635,3293 const_of_contract_call::in_struct_u64_u64,3897,3554 const_of_contract_call::in_struct_u64_u64_u64,4156,3813 const_of_contract_call::isolated_cost_of_in_array_0,956,956 const_of_contract_call::isolated_cost_of_in_array_1,1515,1185 const_of_contract_call::isolated_cost_of_in_array_16,3955,3266 const_of_contract_call::isolated_cost_of_in_array_32,6544,5471 const_of_contract_call::isolated_cost_of_in_array_64,9914,9914 const_of_contract_call::isolated_cost_of_in_array_8,3225,2728 const_of_contract_call::isolated_cost_of_in_b256,1462,1120 const_of_contract_call::isolated_cost_of_in_bool,1358,1047 const_of_contract_call::isolated_cost_of_in_str_0,1451,1140 const_of_contract_call::isolated_cost_of_in_str_1,1547,1237 const_of_contract_call::isolated_cost_of_in_str_16,1552,1241 const_of_contract_call::isolated_cost_of_in_str_32,1553,1242 const_of_contract_call::isolated_cost_of_in_str_8,1551,1241 const_of_contract_call::isolated_cost_of_in_tuple_0,820,820 const_of_contract_call::isolated_cost_of_in_tuple_1,1412,1090 const_of_contract_call::isolated_cost_of_in_tuple_2,1615,1304 const_of_contract_call::isolated_cost_of_in_tuple_3,1766,1455 const_of_contract_call::isolated_cost_of_in_tuple_4,1916,1605 const_of_contract_call::isolated_cost_of_in_u16,1428,1117 const_of_contract_call::isolated_cost_of_in_u256,1431,1120 const_of_contract_call::isolated_cost_of_in_u32,1554,1243 const_of_contract_call::isolated_cost_of_in_u64,1336,1025 const_of_contract_call::isolated_cost_of_in_u8,1352,1041 ``` ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent 7d876d1 commit 4e16bed

File tree

5 files changed

+139
-133
lines changed

5 files changed

+139
-133
lines changed

justfile

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,37 @@ collect-gas-usage:
3636
cargo r -p test --release -- --verbose --forc-test-only | ./scripts/compare-gas-usage/extract-gas-usage.sh
3737

3838
# This recipe should be used on snapshot tests that contains gas usage from `forc test`,
39-
# because it will extract gas usage from all versions of the file and generate an html interactive report.
39+
# because it will extract gas usage from all versions of the file
40+
# revision_range: as used in git to select the versions of the file that gas will be extracted
4041
# path: path to file to extract gas usage
41-
# open: "-o" will open the default browser showing the report
42+
# report: csv or html
43+
# open: for "html", "-o" will open the report in the default browser
4244
[linux]
4345
[group('benchmark')]
44-
collect-historic-gas-usage path open:
46+
collect-historic-gas-usage revision_range path report open="":
4547
#! /bin/bash
4648
mkdir -p target
47-
rm target/a.csv
48-
rm target/a.html
49+
rm target/a.csv &>> /dev/null
50+
rm target/a.html &>> /dev/null
4951
echo "test,gas,commit" > target/a.csv
50-
for HASH in `git log --format='%H' -- {{path}}`; do
52+
for HASH in `git log --format='%H' {{revision_range}} -- {{path}}`; do
5153
TIMESTAMP=$(git show -s --format='%as-%ct-%H' "$HASH")
5254
git --no-pager show "$HASH:{{path}}" | bash -c "scripts/compare-gas-usage/extract-gas-usage.sh $TIMESTAMP" >> target/a.csv
5355
done
54-
./scripts/csv2html/csv2html.sh target/a.csv >> target/a.html
55-
if [ -n "{{open}}" ]; then
56-
if which xdg-open &>> /dev/null
57-
then
58-
xdg-open target/a.html
59-
elif which gnome-open &>> /dev/null
60-
then
61-
gnome-open target/a.html
56+
57+
if [ "{{report}}" = "html" ]; then
58+
./scripts/csv2html/csv2html.sh target/a.csv >> target/a.html
59+
if [ -n "{{open}}" ]; then
60+
if which xdg-open &>> /dev/null
61+
then
62+
xdg-open target/a.html
63+
elif which gnome-open &>> /dev/null
64+
then
65+
gnome-open target/a.html
66+
fi
6267
fi
68+
else
69+
clipivot max target/a.csv --rows=test --cols=commit --val=gas > target/b.csv
6370
fi
6471

6572
[group('build')]

scripts/csv2html/csv2html.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ tail -n +2 "$1" | sed -e 's/^/<tr><td>/' -e 's/,/<\/td><td>/g' -e 's/$/<\/td><\/
5757
echo " </tbody>
5858
</table>
5959
<body>
60-
</html>"
60+
</html>"

sway-lib-std/src/codec.sw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,17 +5359,17 @@ where
53595359
{
53605360
let first_parameter = encode(method_name);
53615361
let second_parameter = encode(args);
5362-
let params = encode((
5362+
let params = (
53635363
contract_id,
53645364
asm(a: first_parameter.ptr()) {
53655365
a: u64
53665366
},
53675367
asm(a: second_parameter.ptr()) {
53685368
a: u64
53695369
},
5370-
));
5370+
);
53715371

5372-
__contract_call(params.ptr(), coins, asset_id, gas);
5372+
__contract_call(&params, coins, asset_id, gas);
53735373
let ptr = asm() {
53745374
ret: raw_ptr
53755375
};

test/src/e2e_vm_tests/test_programs/should_pass/language/panic_expression/panicking_contract/stdout.snap

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
source: test/src/snapshot/mod.rs
3-
assertion_line: 266
43
---
54
> forc test --path test/src/e2e_vm_tests/test_programs/should_pass/language/panic_expression/panicking_contract --test-threads 1 --logs --reverts
65
exit status: 0
@@ -9,25 +8,25 @@ output:
98
Compiling library std (test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-core)
109
Compiling library panicking_lib (test/src/e2e_vm_tests/test_programs/should_pass/language/panic_expression/panicking_lib)
1110
Compiling contract panicking_contract (test/src/e2e_vm_tests/test_programs/should_pass/language/panic_expression/panicking_contract)
12-
Finished debug [unoptimized + fuel] target(s) [8.92 KB] in ???
11+
Finished debug [unoptimized + fuel] target(s) [8.512 KB] in ???
1312
Running 12 tests, filtered 0 tests
1413

1514
tested -- panicking_contract
1615

17-
test test_panicking_in_contract_self_impl ... ok (???, 1618 gas)
16+
test test_panicking_in_contract_self_impl ... ok (???, 1245 gas)
1817
revert code: 8000000000000001
1918
├─ panic message: panicking in contract self impl
2019
├─ panicked: in <Contract as PanickingContractAbi>::panicking_in_contract_self_impl
2120
│ └─ at panicking_contract@1.2.3, src/main.sw:22:9
22-
test test_directly_panicking_method ... ok (???, 2147 gas)
21+
test test_directly_panicking_method ... ok (???, 1774 gas)
2322
revert code: 8080000000000002
2423
├─ panic message: Error C.
2524
├─ panic value: C(true)
2625
├─ panicked: in <Contract as Abi>::directly_panicking_method
2726
│ └─ at panicking_contract@1.2.3, src/main.sw:28:9
2827
decoded log values:
2928
C(true), log rb: 5503570629422409978
30-
test test_nested_panic_inlined ... ok (???, 3843 gas)
29+
test test_nested_panic_inlined ... ok (???, 3470 gas)
3130
revert code: 830000000540a013
3231
├─ panic message: Error E.
3332
├─ panic value: E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }])
@@ -39,7 +38,7 @@ C(true), log rb: 5503570629422409978
3938
└─ at panicking_contract@1.2.3, src/main.sw:32:9
4039
decoded log values:
4140
E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }]), log rb: 5503570629422409978
42-
test test_nested_panic_inlined_same_revert_code ... ok (???, 3843 gas)
41+
test test_nested_panic_inlined_same_revert_code ... ok (???, 3470 gas)
4342
revert code: 830000000540a013
4443
├─ panic message: Error E.
4544
├─ panic value: E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }])
@@ -51,7 +50,7 @@ E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString
5150
└─ at panicking_contract@1.2.3, src/main.sw:32:9
5251
decoded log values:
5352
E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }]), log rb: 5503570629422409978
54-
test test_nested_panic_non_inlined ... ok (???, 4171 gas)
53+
test test_nested_panic_non_inlined ... ok (???, 3798 gas)
5554
revert code: 838000000680c818
5655
├─ panic message: Error E.
5756
├─ panic value: E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }])
@@ -63,7 +62,7 @@ E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString
6362
└─ at panicking_contract@1.2.3, src/main.sw:40:9
6463
decoded log values:
6564
E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }]), log rb: 5503570629422409978
66-
test test_nested_panic_non_inlined_same_revert_code ... ok (???, 4171 gas)
65+
test test_nested_panic_non_inlined_same_revert_code ... ok (???, 3798 gas)
6766
revert code: 838000000680c818
6867
├─ panic message: Error E.
6968
├─ panic value: E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }])
@@ -75,7 +74,7 @@ E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { d
7574
└─ at panicking_contract@1.2.3, src/main.sw:40:9
7675
decoded log values:
7776
E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }]), log rb: 5503570629422409978
78-
test test_generic_panic_with_unit ... ok (???, 2842 gas)
77+
test test_generic_panic_with_unit ... ok (???, 2469 gas)
7978
revert code: 828000000000800f
8079
├─ panic value: ()
8180
├─ panicked: in panicking_lib::generic_panic
@@ -84,7 +83,7 @@ E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { d
8483
└─ at panicking_contract@1.2.3, src/main.sw:48:9
8584
decoded log values:
8685
(), log rb: 3330666440490685604
87-
test test_generic_panic_with_unit_same_revert_code ... ok (???, 2842 gas)
86+
test test_generic_panic_with_unit_same_revert_code ... ok (???, 2469 gas)
8887
revert code: 828000000000800f
8988
├─ panic value: ()
9089
├─ panicked: in panicking_lib::generic_panic
@@ -93,7 +92,7 @@ E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { d
9392
└─ at panicking_contract@1.2.3, src/main.sw:48:9
9493
decoded log values:
9594
(), log rb: 3330666440490685604
96-
test test_generic_panic_with_str ... ok (???, 2794 gas)
95+
test test_generic_panic_with_str ... ok (???, 2421 gas)
9796
revert code: 818000000000700d
9897
├─ panic message: generic panic with string
9998
├─ panicked: in panicking_lib::generic_panic
@@ -102,7 +101,7 @@ E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { d
102101
└─ at panicking_contract@1.2.3, src/main.sw:56:9
103102
decoded log values:
104103
AsciiString { data: "generic panic with string" }, log rb: 10098701174489624218
105-
test test_generic_panic_with_different_str_same_revert_code ... ok (???, 2335 gas)
104+
test test_generic_panic_with_different_str_same_revert_code ... ok (???, 1962 gas)
106105
revert code: 8180000000004007
107106
├─ panic message: generic panic with different string
108107
├─ panicked: in panicking_lib::generic_panic
@@ -111,7 +110,7 @@ AsciiString { data: "generic panic with string" }, log rb: 10098701174489624218
111110
└─ at panicking_contract@1.2.3, src/main.sw:60:9
112111
decoded log values:
113112
AsciiString { data: "generic panic with different string" }, log rb: 10098701174489624218
114-
test test_generic_panic_with_error_type_enum ... ok (???, 2519 gas)
113+
test test_generic_panic_with_error_type_enum ... ok (???, 2146 gas)
115114
revert code: 8200000000005009
116115
├─ panic message: Error A.
117116
├─ panic value: A
@@ -121,7 +120,7 @@ AsciiString { data: "generic panic with different string" }, log rb: 10098701174
121120
└─ at panicking_contract@1.2.3, src/main.sw:64:9
122121
decoded log values:
123122
A, log rb: 5503570629422409978
124-
test test_generic_panic_with_error_type_enum_different_variant_same_revert_code ... ok (???, 2751 gas)
123+
test test_generic_panic_with_error_type_enum_different_variant_same_revert_code ... ok (???, 2378 gas)
125124
revert code: 820000000000600b
126125
├─ panic message: Error B.
127126
├─ panic value: B(42)
@@ -143,93 +142,93 @@ output:
143142
Compiling library std (test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-core)
144143
Compiling library panicking_lib (test/src/e2e_vm_tests/test_programs/should_pass/language/panic_expression/panicking_lib)
145144
Compiling contract panicking_contract (test/src/e2e_vm_tests/test_programs/should_pass/language/panic_expression/panicking_contract)
146-
Finished release [optimized + fuel] target(s) [7.416 KB] in ???
145+
Finished release [optimized + fuel] target(s) [7.024 KB] in ???
147146
Running 12 tests, filtered 0 tests
148147

149148
tested -- panicking_contract
150149

151-
test test_panicking_in_contract_self_impl ... ok (???, 1183 gas)
150+
test test_panicking_in_contract_self_impl ... ok (???, 869 gas)
152151
revert code: 8000000000000000
153152
├─ panic message: panicking in contract self impl
154153
└─ panicked: in <Contract as PanickingContractAbi>::panicking_in_contract_self_impl
155154
└─ at panicking_contract@1.2.3, src/main.sw:22:9
156-
test test_directly_panicking_method ... ok (???, 1605 gas)
155+
test test_directly_panicking_method ... ok (???, 1291 gas)
157156
revert code: 8080000000000000
158157
├─ panic message: Error C.
159158
├─ panic value: C(true)
160159
└─ panicked: in <Contract as Abi>::directly_panicking_method
161160
└─ at panicking_contract@1.2.3, src/main.sw:28:9
162161
decoded log values:
163162
C(true), log rb: 5503570629422409978
164-
test test_nested_panic_inlined ... ok (???, 2851 gas)
163+
test test_nested_panic_inlined ... ok (???, 2537 gas)
165164
revert code: 8300000000000000
166165
├─ panic message: Error E.
167166
├─ panic value: E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }])
168167
└─ panicked: in panicking_lib::nested_panic_inlined
169168
└─ at panicking_lib, src/lib.sw:35:5
170169
decoded log values:
171170
E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }]), log rb: 5503570629422409978
172-
test test_nested_panic_inlined_same_revert_code ... ok (???, 2851 gas)
171+
test test_nested_panic_inlined_same_revert_code ... ok (???, 2537 gas)
173172
revert code: 8300000000000000
174173
├─ panic message: Error E.
175174
├─ panic value: E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }])
176175
└─ panicked: in panicking_lib::nested_panic_inlined
177176
└─ at panicking_lib, src/lib.sw:35:5
178177
decoded log values:
179178
E([AsciiString { data: "to have" }, AsciiString { data: "strings" }, AsciiString { data: "in error enum variants" }]), log rb: 5503570629422409978
180-
test test_nested_panic_non_inlined ... ok (???, 3081 gas)
179+
test test_nested_panic_non_inlined ... ok (???, 2767 gas)
181180
revert code: 8380000000000000
182181
├─ panic message: Error E.
183182
├─ panic value: E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }])
184183
└─ panicked: in panicking_lib::nested_panic_non_inlined
185184
└─ at panicking_lib, src/lib.sw:41:9
186185
decoded log values:
187186
E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }]), log rb: 5503570629422409978
188-
test test_nested_panic_non_inlined_same_revert_code ... ok (???, 3081 gas)
187+
test test_nested_panic_non_inlined_same_revert_code ... ok (???, 2767 gas)
189188
revert code: 8380000000000000
190189
├─ panic message: Error E.
191190
├─ panic value: E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }])
192191
└─ panicked: in panicking_lib::nested_panic_non_inlined
193192
└─ at panicking_lib, src/lib.sw:41:9
194193
decoded log values:
195194
E([AsciiString { data: "this" }, AsciiString { data: "is not" }, AsciiString { data: "the best practice" }]), log rb: 5503570629422409978
196-
test test_generic_panic_with_unit ... ok (???, 2053 gas)
195+
test test_generic_panic_with_unit ... ok (???, 1739 gas)
197196
revert code: 8280000000000000
198197
├─ panic value: ()
199198
└─ panicked: in panicking_lib::generic_panic
200199
└─ at panicking_lib, src/lib.sw:74:5
201200
decoded log values:
202201
(), log rb: 3330666440490685604
203-
test test_generic_panic_with_unit_same_revert_code ... ok (???, 2053 gas)
202+
test test_generic_panic_with_unit_same_revert_code ... ok (???, 1739 gas)
204203
revert code: 8280000000000000
205204
├─ panic value: ()
206205
└─ panicked: in panicking_lib::generic_panic
207206
└─ at panicking_lib, src/lib.sw:74:5
208207
decoded log values:
209208
(), log rb: 3330666440490685604
210-
test test_generic_panic_with_str ... ok (???, 2057 gas)
209+
test test_generic_panic_with_str ... ok (???, 1743 gas)
211210
revert code: 8180000000000000
212211
├─ panic message: generic panic with string
213212
└─ panicked: in panicking_lib::generic_panic
214213
└─ at panicking_lib, src/lib.sw:74:5
215214
decoded log values:
216215
AsciiString { data: "generic panic with string" }, log rb: 10098701174489624218
217-
test test_generic_panic_with_different_str_same_revert_code ... ok (???, 1739 gas)
216+
test test_generic_panic_with_different_str_same_revert_code ... ok (???, 1425 gas)
218217
revert code: 8180000000000000
219218
├─ panic message: generic panic with different string
220219
└─ panicked: in panicking_lib::generic_panic
221220
└─ at panicking_lib, src/lib.sw:74:5
222221
decoded log values:
223222
AsciiString { data: "generic panic with different string" }, log rb: 10098701174489624218
224-
test test_generic_panic_with_error_type_enum ... ok (???, 1860 gas)
223+
test test_generic_panic_with_error_type_enum ... ok (???, 1546 gas)
225224
revert code: 8200000000000000
226225
├─ panic message: Error A.
227226
├─ panic value: A
228227
└─ panicked: in panicking_lib::generic_panic
229228
└─ at panicking_lib, src/lib.sw:74:5
230229
decoded log values:
231230
A, log rb: 5503570629422409978
232-
test test_generic_panic_with_error_type_enum_different_variant_same_revert_code ... ok (???, 2023 gas)
231+
test test_generic_panic_with_error_type_enum_different_variant_same_revert_code ... ok (???, 1709 gas)
233232
revert code: 8200000000000000
234233
├─ panic message: Error B.
235234
├─ panic value: B(42)

0 commit comments

Comments
 (0)