Skip to content

Optimise get_config for trivial types - #7682

Merged
ironcev merged 18 commits into
masterfrom
xunilrj/opt-get-config
Oct 8, 2026
Merged

ironcev merged 18 commits into
masterfrom
xunilrj/opt-get-config

Conversation

@xunilrj

@xunilrj xunilrj commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR optimize access to trivially decodable configurables.

We know that decode for these configurables is essentially a noop. So now we do not run their decode and simply point to the configurable section directly.

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

codspeed Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing xunilrj/opt-get-config (ebca105) with master (f26c42c)

Open in CodSpeed

@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

@xunilrj
xunilrj force-pushed the xunilrj/opt-get-config branch from a60b3ba to e8f3a2a Compare July 20, 2026 13:27
@xunilrj
xunilrj temporarily deployed to fuel-sway-bot July 20, 2026 13:27 — with GitHub Actions Inactive
@xunilrj
xunilrj temporarily deployed to fuel-sway-bot July 20, 2026 13:59 — with GitHub Actions Inactive
@xunilrj

xunilrj commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor Author
order-book binary size:
Before: 124.56 KB
After: 124.12 KB (0.3% better)

fuel-o2-exports

Improvements Regressions
Count 32 1
Average 0.61% -0.04%
Median 0.64% -0.04%
Max 1.35% -0.04%
Min 0.04% -0.04%

@xunilrj xunilrj mentioned this pull request Jul 21, 2026
3 of 8 tasks
ironcev added a commit that referenced this pull request Jul 23, 2026
## Description

Whilst trying to improve #7682, I
came across the following bug:

SROA was generating invalid IR when an aggregated had `load`s across
multiple blocks. When generating the scalar accesses, the older
algorithm was gathering only the "last" block that had access, and
incorrectly generating `load`s pointing to this last block, even when
the `load` was from a previous block. A "use-before-def" problem. (see
sway-ir/tests/sroa/cross_block_gep_reuse.ir).

To verify this issue this PR also creates an "SSA dominance check". We
check if all "uses" are dominated by all its "defs". But this check is
expensive, so, for the moment, this check is opt-in. Below we have some
timings to justify that:

```
dominance check off:
> hyperfine "cargo r -p forc -r -- build --path fuel-o2-exports/contracts/order-book --release"
Benchmark 1: cargo r -p forc -r -- build --path fuel-o2-exports/contracts/order-book --release
  Time (mean ± σ):     11.213 s ±  0.100 s    [User: 8.347 s, System: 1.095 s]
  Range (min … max):   11.105 s … 11.383 s    10 runs

dominance check on:
> SWAY_FORCE_VERIFY_IR=true hyperfine "cargo r -p forc -r -- build --path fuel-o2-exports/contracts/order-book --release"
Benchmark 1: cargo r -p forc -r -- build --path fuel-o2-exports/contracts/order-book --release
  Time (mean ± σ):     16.663 s ±  0.577 s    [User: 13.563 s, System: 1.121 s]
  Range (min … max):   16.358 s … 18.271 s    10 runs
```

This PR also removes `DCE` and `MEM2REG` passes. from the SROA test.
They were there to facilitate `filecheck` directives. As we do not use
them anymore, seeing the diff as it is, is actually better.

## Checklist

- [ ] I have linked to any relevant issues.
- [x] 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.
- [ ] 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.

---------

Co-authored-by: Igor Rončević <ironcev@hotmail.com>
@xunilrj
xunilrj force-pushed the xunilrj/opt-get-config branch from e3c79a8 to 98d47fd Compare August 24, 2026 18:28
@xunilrj
xunilrj deployed to fuel-sway-bot August 24, 2026 18:28 — with GitHub Actions Active
@xunilrj
xunilrj force-pushed the xunilrj/opt-get-config branch from 98d47fd to 3f1dd93 Compare August 24, 2026 23:41
@xunilrj
xunilrj deployed to fuel-sway-bot August 24, 2026 23:41 — with GitHub Actions Active
@xunilrj

xunilrj commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

order book

Improvements Regressions
Count 25 10
Average 0.90% -0.06%
Median 0.96% -0.06%
Max 1.52% -0.09%
Min 0.15% -0.03%

"single_level/total_gas",1588956,1590246,-0.08
"single_level/gas_per_match",3177,3180,-0.09
"multi_level/total_gas",2094872,2096400,-0.07
"multi_level/gas_per_match",4028,4031,-0.07
"max_throughput_worst_case/total_gas",20973262,20979761,-0.03
"max_throughput_worst_case/gas_per_match",17536,17541,-0.03

trade account

Improvements Regressions
Count 21 —
Average 0.18% —
Median 0.17% —
Max 0.27% —
Min 0.08% —

@xunilrj
xunilrj force-pushed the xunilrj/opt-get-config branch from 3f1dd93 to 2245cc4 Compare September 24, 2026 16:11
@xunilrj
xunilrj deployed to fuel-sway-bot September 24, 2026 16:11 — with GitHub Actions Active
@xunilrj

xunilrj commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

I had to remove the idea of having "$cs" for now. It was causing some annoying regressions exactly in hpt paths. The issue is that we were decreasing the allocation pool, and one of the affected methods was exactly in a important method inside the order-book contract.

Nor order-book, nor trade-account contracts have trivial configurables after the limit of 12 bit offsets. We can try to improve this case later in multiple ways without reserving a new register.

fuel-o2-exports / order-book

Improvements Regressions
Count 35 —
Average 0.50% —
Median 0.52% —
Max 0.77% —
Min 0.21% —

Distribution

Histogram for Percentage (bars: 10, sum: 35n, max: 8n):

>= 0.21   <  0.266  |2n   5.71%|■■■■■■■■■■                             |
>= 0.266  <  0.322  |8n  22.86%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■|
>= 0.322  <  0.378  |2n   5.71%|■■■■■■■■■■                             |
>= 0.378  <  0.434  |3n   8.57%|■■■■■■■■■■■■■■■                        |
>= 0.434  <  0.49   |1n   2.86%|■■■■■                                  |
>= 0.49   <  0.546  |2n   5.71%|■■■■■■■■■■                             |
>= 0.546  <  0.6020 |2n   5.71%|■■■■■■■■■■                             |
>= 0.6020 <  0.6580 |5n  14.29%|■■■■■■■■■■■■■■■■■■■■■■■■■              |
>= 0.6580 <  0.7140 |3n   8.57%|■■■■■■■■■■■■■■■                        |
>= 0.7140 <= 0.77   |7n  20.00%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■    |

fuel-o2-exports / trade-account

Improvements Regressions
Count 21 —
Average 0.24% —
Median 0.24% —
Max 0.36% —
Min 0.10% —

Distribution

Histogram for Percentage (bars: 10, sum: 21n, max: 4n):

>= 0.1    <  0.126  |2n   9.52%|■■■■■■■■■■■■■■■■■■■■                   |
>= 0.126  <  0.152  |1n   4.76%|■■■■■■■■■■                             |
>= 0.152  <  0.178  |4n  19.05%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■|
>= 0.178  <  0.204  |2n   9.52%|■■■■■■■■■■■■■■■■■■■■                   |
>= 0.204  <  0.2299 |0n   0.00%|                                       |
>= 0.2299 <  0.256  |3n  14.29%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■         |
>= 0.256  <  0.2820 |2n   9.52%|■■■■■■■■■■■■■■■■■■■■                   |
>= 0.2820 <  0.3080 |0n   0.00%|                                       |
>= 0.3080 <  0.3340 |4n  19.05%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■|
>= 0.3340 <= 0.36   |3n  14.29%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■         |

@xunilrj
xunilrj force-pushed the xunilrj/opt-get-config branch from 2245cc4 to 97a6715 Compare September 24, 2026 16:36
@xunilrj
xunilrj deployed to fuel-sway-bot September 24, 2026 16:37 — with GitHub Actions Active
@xunilrj
xunilrj marked this pull request as ready for review September 24, 2026 17:34
@xunilrj
xunilrj requested review from a team as code owners September 24, 2026 17:34
@xunilrj
xunilrj force-pushed the xunilrj/opt-get-config branch from 97a6715 to ebca105 Compare October 5, 2026 12:39
@xunilrj
xunilrj deployed to fuel-sway-bot October 5, 2026 12:40 — with GitHub Actions Active
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes performance Everything related to performance, speed wise or memory wise. labels Oct 8, 2026
@ironcev

ironcev commented Oct 8, 2026

Copy link
Copy Markdown
Member

👍

@ironcev
ironcev merged commit 102ab6c into master Oct 8, 2026
42 checks passed
@ironcev
ironcev deleted the xunilrj/opt-get-config branch October 8, 2026 11:35

This branch was successfully deployed

1 active deployment
fuel-sway-bot — ebca1055 Deployed Oct 5, 2026 by xunilrj via forc-run-benchmarks #27208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: ir IRgen and sway-ir including optimization passes compiler General compiler. Should eventually become more specific as the issue is triaged performance Everything related to performance, speed wise or memory wise.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants