Latest Results
Optimize type casting by using `__transmute` instead of `asm` blocks (#7675)
## Description
This PR improves gas costs and bytecode sizes by consistently replacing
`asm`-based conversions of _reference types_ in `std` with
`__transmute`.
Note that **copy-types are still converted using `asm` blocks**, because
currently we didn't extend `__transmute` to handle copy-types without
demoting transmuted values to stack and actually casting pointers. This
gives a performance penalty when transmuting copy-types which we don't
want to have.
As expected, removing `asm` blocks unlocked existing IR performance
optimizations and resulted in performance improvements given in the
comment below.
Note that we might think of temporarily forbidding using `__transmute`
with copy-types until it is properly supported. But we have code in
`ops.sw` where `__transmute` must be used to convert between copy-types,
because the operator trait methods must be const-evaluable and if they
use `asm` for conversion, they cannot be. Historically, making them
const-evaluable was the reason for adding `__transmute` in the first
place.
Note that in the future, we plan to improve IR optimizations by letting
them be aware of "safe `asm` blocks". Pure conversion blocks will be
considered safe. That improvement would likely bring the same
performance benefits as rolling out `__transmute`, but:
- it will take some time before we get it implemented,
- regardless, `__transmute` is the expected way to convert types and we
should use it consistentlty across the codebase.
Note that the PR changes snapshot files in the `sway-ir` tests. These
changes are not related to this PR, but likely to the snapshots not
being updated because of the `insta` checks being silent. For more info
see
https://github.com/FuelLabs/sway/pull/7666#pullrequestreview-4589675640.
## 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)
- [ ] 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. Latest Branches
0%
xunilrj/removing-cli-verify 0%
xunilrj/fix-opt-passes-convergence -16%
ironcev/refactor-std-tests © 2026 CodSpeed Technology