Skip to content

Conversation

@bitzoic
Copy link
Member

@bitzoic bitzoic commented Sep 30, 2025

Description

Legacy functionality from the storage API now allocates more memory than required for the read and write functions. This allocation has been reduced to the correct amounts. Reduces unnecessary byte allocation by 8x.

Performance gains

Comparing 'e2e-gas-usages':

Improvements Regressions
Count 9
Average 0.44%
Median 0.35%
Max 1.10%
Min 0.17%
Test Before After Percentage
should_pass/empty_fields_in_storage_struct (test.toml)::test_read_write_bytes 11248 11221 0.24%
should_pass/empty_fields_in_storage_struct (test.toml)::test_read_write_map 8042 8027 0.19%
should_pass/empty_fields_in_storage_struct (test.toml)::test_read_write_vec 11696 11660 0.31%
should_pass/language/storage_slot_sized (test.toml)::test_store_something 8020 8006 0.17%
should_pass/stdlib/storage_vec_insert (test.toml)::test_test_function 2925 2903 0.75%
should_pass/test_contracts/basic_storage (test.toml)::collect_basic_storage_contract_gas_usages 37636 37472 0.44%
should_pass/test_contracts/increment_contract (test.toml)::collect_incrementor_contract_gas_usages 2015 2006 0.45%
should_pass/test_contracts/storage_access_contract (test.toml)::collect_storage_access_contract_gas_usages 50372 50198 0.35%
should_pass/test_contracts/storage_enum_contract (test.toml)::collect_storage_enum_contract_gas_usages 22860 22609 1.10%

Comparing 'e2e-bytecode-sizes':

Improvements Regressions
Count 33
Average 0.66%
Median 0.67%
Max 1.06%
Min 0.16%
Test Before After Percentage
should_pass/empty_fields_in_storage_struct (test.toml) 9968 9952 0.16%
should_pass/language/fallback_only (test.toml) 1504 1488 1.06%
should_pass/language/generics_in_contract (test.toml) 1824 1816 0.44%
should_pass/language/storage_slot_sized (test.toml) 4016 3984 0.80%
should_pass/static_analysis/cei_pattern_violation (test.toml) 968 960 0.83%
should_pass/static_analysis/cei_pattern_violation_in_codeblocks_other_than_in_functions (test.toml) 1200 1192 0.67%
should_pass/static_analysis/cei_pattern_violation_in_func_app-1 (test.toml) 1192 1184 0.67%
should_pass/static_analysis/cei_pattern_violation_in_func_app-2 (test.toml) 1192 1184 0.67%
should_pass/static_analysis/cei_pattern_violation_in_func_app-3 (test.toml) 1192 1184 0.67%
should_pass/static_analysis/cei_pattern_violation_in_if_statement-1 (test.toml) 1216 1208 0.66%
should_pass/static_analysis/cei_pattern_violation_in_if_statement-2 (test.toml) 1192 1184 0.67%
should_pass/static_analysis/cei_pattern_violation_in_intrinsic_call (test.toml) 1192 1184 0.67%
should_pass/static_analysis/cei_pattern_violation_in_match_statement-1 (test.toml) 1696 1688 0.47%
should_pass/static_analysis/cei_pattern_violation_in_standalone_function (test.toml) 968 960 0.83%
should_pass/static_analysis/cei_pattern_violation_in_struct (test.toml) 1216 1208 0.66%
should_pass/static_analysis/cei_pattern_violation_in_tuple (test.toml) 1216 1208 0.66%
should_pass/static_analysis/cei_pattern_violation_in_while_loop-1 (test.toml) 1192 1184 0.67%
should_pass/static_analysis/cei_pattern_violation_in_while_loop-2 (test.toml) 1200 1192 0.67%
should_pass/static_analysis/cei_pattern_violation_in_while_loop-3 (test.toml) 1192 1184 0.67%
should_pass/static_analysis/cei_pattern_violation_in_while_loop-4 (test.toml) 1200 1192 0.67%
should_pass/static_analysis/cei_pattern_violation_more_complex_logic (test.toml) 12136 12088 0.40%
should_pass/static_analysis/cei_pattern_violation_storage_map_and_vec (test.toml) 4272 4256 0.37%
should_pass/static_analysis/cei_pattern_violation_storage_struct_read (test.toml) 1224 1216 0.65%
should_pass/static_analysis/cei_pattern_violation_storage_var_read (test.toml) 1568 1560 0.51%
should_pass/static_analysis/cei_pattern_violation_storage_var_update (test.toml) 1104 1096 0.72%
should_pass/stdlib/storage_vec_insert (test.toml) 2808 2792 0.57%
should_pass/storage_into (test.toml) 1192 1184 0.67%
should_pass/supertraits_for_abis_ownable (test.toml) 2600 2584 0.62%
should_pass/test_contracts/basic_storage (test.toml) 27248 27048 0.73%
should_pass/test_contracts/increment_contract (test.toml) 2248 2232 0.71%
should_pass/test_contracts/storage_access_contract (test.toml) 19968 19832 0.68%
should_pass/test_contracts/storage_enum_contract (test.toml) 12600 12472 1.02%
should_pass/test_contracts/storage_namespace (test.toml) 26576 26320 0.96%

Comparing 'in-language-gas-usages':

Improvements Regressions
Count 5
Average 0.09%
Median 0.06%
Max 0.20%
Min 0.06%
Test Before After Percentage
storage_vec_iter_tests::empty_vec_next_returns_none 52083 51978 0.20%
storage_vec_iter_tests::storage_vec_field_for_loop_iteration 1581441 1580524 0.06%
storage_vec_iter_tests::storage_vec_field_nested_for_loop_iteration 11629696 11622275 0.06%
storage_vec_iter_tests::vec_with_elements_for_loop_iteration 24102546 24089241 0.06%
storage_vec_iter_tests::vec_with_elements_next_returns_element 24102277 24088884 0.06%

Checklist

  • 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).
  • 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.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@bitzoic bitzoic self-assigned this Sep 30, 2025
@bitzoic bitzoic requested review from a team as code owners September 30, 2025 16:05
@bitzoic bitzoic added the lib: std Standard library label Sep 30, 2025
DefiCake
DefiCake previously approved these changes Oct 1, 2025
@ironcev ironcev self-assigned this Nov 5, 2025
@ironcev ironcev merged commit 90c8ed2 into master Nov 5, 2025
49 of 79 checks passed
@ironcev ironcev deleted the bitzoic-fix-storage-alloc branch November 5, 2025 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib: std Standard library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants