Skip to content

Improve raw_ptr::write (1/n)#7646

Draft
xunilrj wants to merge 32 commits into
masterfrom
xunilrj/improve-rawptr-write
Draft

Improve raw_ptr::write (1/n)#7646
xunilrj wants to merge 32 commits into
masterfrom
xunilrj/improve-rawptr-write

Conversation

@xunilrj

@xunilrj xunilrj commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

This PR is the first of a series trying to make raw_ptr::write optimal. For now, we tackle the issue that it was not being inlined.

The issue is that we only check for inlining at certain points, and some optimisations were being run after this check, ignoring the inlining even when it made sense.

The solution is to run the optimisation pipeline multiple times, a standard practice. For that, I had to fix other passes that were returning true for modified even when they do not change anything. This allows us to break the loop as early as possible.

Compilation time impact remains to be checked, but we can remove the loop on debug builds if that presents itself as a problem.

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 June 5, 2026 18:26 — with GitHub Actions Inactive
@xunilrj xunilrj changed the title Xunilrj/improve rawptr write Improve raw_ptr::write (1/n) Jun 5, 2026
@xunilrj

xunilrj commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

e2e-gas-usage

Improvements Regressions
Count 1038 51
Average 2.48% -0.92%
Median 0.52% -0.28%
Max 94.39% -5.59%
Min 0.10% -0.01%

e2e-bytecode-size

Improvements Regressions
Count 130 25
Average 11.80% -4.73%
Median 5.44% -3.17%
Max 97.61% -18.34%
Min 0.13% -0.16%

o2-bytecode-size

Improvements Regressions
Count 3 2
Average 2.94% -0.59%
Median 3.30% -0.59%
Max 3.55% -0.92%
Min 1.97% -0.26%

o2-gas-usage

Improvements Regressions
Count 1 1
Average 25.16% -0.42%
Median 25.16% -0.42%
Max 25.16% -0.42%
Min 25.16% -0.42%
Test Before After Percentage
contract_libs::test_u56 480 482 -0.42%
src20-token::storage_sizes_of_stored_types 640 479 25.16%

@xunilrj xunilrj temporarily deployed to fuel-sway-bot June 5, 2026 22:08 — with GitHub Actions Inactive
@codspeed-hq

codspeed-hq Bot commented Jun 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 20.32%

❌ 1 regressed benchmark
✅ 24 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
tokens_for_program 520.2 µs 652.8 µs -20.32%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing xunilrj/improve-rawptr-write (7196d95) with master (52671eb)

Open in CodSpeed

@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 Jun 8, 2026
@ironcev

ironcev commented Jun 8, 2026

Copy link
Copy Markdown
Member

👍

@xunilrj xunilrj temporarily deployed to fuel-sway-bot June 10, 2026 00:44 — with GitHub Actions Inactive
@xunilrj xunilrj temporarily deployed to fuel-sway-bot June 10, 2026 23:55 — with GitHub Actions Inactive
@xunilrj xunilrj temporarily deployed to fuel-sway-bot June 11, 2026 10:52 — with GitHub Actions Inactive
@xunilrj xunilrj temporarily deployed to fuel-sway-bot June 11, 2026 12:09 — with GitHub Actions Inactive
@xunilrj xunilrj temporarily deployed to fuel-sway-bot June 11, 2026 14:45 — with GitHub Actions Inactive
@xunilrj xunilrj mentioned this pull request Jun 11, 2026
8 tasks
ironcev added a commit that referenced this pull request Jun 11, 2026
## Description

This PR is a necessary change for
#7646.

Some IR tests have a bug: their harness is expecting some passes to
return `modified = true` even when the pass is not modifying anything.
To make sure that #7646 is NOT changing the optimisation itself, but
only fixing the `modified` flag, I am creating this PR.

The idea is that #7646 snapshot tests will have only the flag changed,
not their optimisation.

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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).
- [ ] 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/improve-rawptr-write branch from 5d5a052 to 7196d95 Compare June 12, 2026 12:10
@xunilrj xunilrj temporarily deployed to fuel-sway-bot June 12, 2026 12:10 — with GitHub Actions Inactive
xunilrj added a commit that referenced this pull request Jun 17, 2026
## Description

This PR is another prelude to
#7646.

We discovered that `memcpyopt` does not work when we run it multiple
times. The cause is that we bail the optimisation when a symbol has more
than one write. This is correct, but we were only considering 'store'.

Now we are correctly also considering all other ways to write into
"symbols".

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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).
- [ ] I have requested a review from the relevant team or maintainers.
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