Skip to content

Optimise get_config for trivial types#7682

Draft
xunilrj wants to merge 1 commit into
masterfrom
xunilrj/opt-get-config
Draft

Optimise get_config for trivial types#7682
xunilrj wants to merge 1 commit into
masterfrom
xunilrj/opt-get-config

Conversation

@xunilrj

@xunilrj xunilrj commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

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.

@xunilrj
xunilrj temporarily deployed to fuel-sway-bot July 14, 2026 13:29 — with GitHub Actions Inactive
@codspeed-hq

codspeed-hq Bot commented Jul 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing xunilrj/opt-get-config (a60b3ba) with master (bd7c483)

Open in CodSpeed

@xunilrj

xunilrj commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Comparing 'e2e-gas-usages':

Improvements Regressions
Count 6
Average 6.74%
Median 2.94%
Max 18.33%
Min 2.28%
Test Before After Percentage
should_pass/language/associated_const_in_decls_of_other_constants (test.dynamic_storage.toml)::test 1381 1343 2.75%
should_pass/language/associated_const_in_decls_of_other_constants (test.toml)::test 1381 1343 2.75%
should_pass/language/configurable_consts (test.toml) 1446 1413 2.28%
should_pass/language/configurable_tests (test.toml)::t 2011 1948 3.13%
should_pass/language/shadowing/shadowed_glob_imports (test.toml) 60 49 18.33%
should_pass/language/u256/u256_abi (test.toml) 107 95 11.21%

Comparing 'e2e-bytecode-sizes':

Improvements Regressions
Count 8
Average 12.21%
Median 9.80%
Max 25.00%
Min 1.79%
Test Before After Percentage
should_pass/language/asm_uninitialized_register_shadows_item (test.toml) 208 168 19.23%
should_pass/language/associated_const_in_decls_of_other_constants (test.dynamic_storage.toml) 408 368 9.80%
should_pass/language/associated_const_in_decls_of_other_constants (test.toml) 408 368 9.80%
should_pass/language/attributes_all_in_one (test.dynamic_storage.toml) 472 432 8.47%
should_pass/language/attributes_all_in_one (test.toml) 472 432 8.47%
should_pass/language/configurable_consts (test.toml) 3584 3520 1.79%
should_pass/language/shadowing/shadowed_glob_imports (test.toml) 128 96 25.00%
should_pass/language/u256/u256_abi (test.toml) 264 224 15.15%

Comparing 'in-language-gas-usages':

Improvements Regressions
Count
Average
Median
Max
Min

Comparing 'in-language-bytecode-sizes':

Improvements Regressions
Count
Average
Median
Max
Min

Comparing 'bytecode-sizes' for project 'o2':

Improvements Regressions
Count 1
Average 0.32%
Median 0.32%
Max 0.32%
Min 0.32%
Test Before After Percentage
./contracts/order-book 60864 60672 0.32%

Comparing 'gas-usages' for project 'o2':

Improvements Regressions
Count
Average
Median
Max
Min

@xunilrj

xunilrj commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

I think I found the reason for the regressions. This is an example from o2.

get_config before this optimization generates just one ADDI, as apps normally do not have enough configurables to overflow ADDI immediate argument. With the new optimization, on the other hand, apps normally DO have enough bytes in their data section to overflow it, so we end-up with two instructions: MOVI and ADD.

BEFORE

addi $r0 $ssp i1              ; get address of configurable BASE_ASSET

0x00001808 ADDI R52 $ssp 0x1                               ;; [80, 208, 64, 1]

AFTER

addr $r0 data_Configurable_1  ; get address of configurable BASE_ASSET

0x00001630 MOVI R52 0xd30                                  ;; [114, 208, 13, 48]
0x00001634 ADD R52 R52 R63                                 ;; [16, 211, 79, 192]

The regression then occurs when the number of access compensates the gain of removing the decode.

@ironcev

ironcev commented Jul 15, 2026

Copy link
Copy Markdown
Member

@xunilrj Regarding the large data section, it is likely we can improve there in general. E.g., I've noticed cases where we have a large number of u64s in the data section: #7612

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants