Skip to content

Conversation

@xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Nov 20, 2025

Description

Continuation of #7488.

This PR introduces the option for each type to control its own is_trivial.

Primitive data types have direct implementation (only decoding bool is false, as we need to guarantee its value is zero or one).

Structs, tuples, arrays etc... are trivial if their runtime representation and "inner types" allow for trivial encoding or decoding.

Enums are more complicated as we need to control that the enum tag is valid; they are not trivial.

String arrays are not trivially encoded/decoded for backwards compatibility with "encoding v0" that needs padding in some cases.

Some tests are showing a small regression (6 gas), which comes from the introduced "if" not being optimised away. I want to solve this in another PR, where the "if" condition will come from a const, and IR generation will guarantee that only one branch will ever be emitted.

Snapshot "echo"

Small QOL of snapshot was introduced with the "echo" command. It just prints the message directly, wrapping on 80 chars. The idea is to explain what the snapshot is trying to test.

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.

Note

Add per-type trivial encode/decode flags and use raw_ptr fast paths in ABI (encode/decode) with supporting changes to codec, String/Vec, and tests.

  • std/codec:
    • Introduce AbiEncode::is_encode_trivial and AbiDecode::is_decode_trivial; add helpers is_encode_trivial/is_decode_trivial.
    • Switch encode/abi_decode to branch on triviality; add decode_from_raw_ptr and raw-ptr-based decode_* helpers.
    • Make BufferReader parameter accessors return raw_ptr; minor refactors to use raw ptr copies.
    • Implement triviality for primitives, arrays/tuples (conditional), str[strN] non-trivial, enums non-trivial.
  • std/string & std/vec: implement trivial encode/decode markers (non-trivial) and adapt codec impls.
  • Tests/fixtures:
    • Update snapshots (IR/ASM/bytecode/gas), JSON ABI offsets, contract/predicate IDs, and logging expectations to match new encoding paths.

Written by Cursor Bugbot for commit dddd944. This will update automatically on new commits. Configure here.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 20, 2025

CodSpeed Performance Report

Merging #7501 will degrade performances by 12.57%

Comparing xunilrj/trivial-fns-codec-traits (9f6ed6e) with master (b4fa78d)

Summary

❌ 1 regression
✅ 24 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
compile 4.7 s 5.3 s -12.57%

@xunilrj xunilrj force-pushed the xunilrj/trivial-fns-codec-traits branch from 02e1c5c to 182bf4a Compare November 22, 2025 20:56
@xunilrj xunilrj self-assigned this Nov 23, 2025
@xunilrj xunilrj marked this pull request as ready for review November 23, 2025 18:09
@xunilrj xunilrj requested review from a team as code owners November 23, 2025 18:09
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 7

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@JoshuaBatty
Copy link
Member

-13.24% compile time regression is a bit unfortunate. Any way we can get this number down a bit?

@xunilrj xunilrj force-pushed the xunilrj/trivial-fns-codec-traits branch from e7086e6 to 9f6ed6e Compare December 16, 2025 17:04
@xunilrj xunilrj merged commit 6cc563d into master Dec 16, 2025
48 checks passed
@xunilrj xunilrj deleted the xunilrj/trivial-fns-codec-traits branch December 16, 2025 23:43
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen breaking May cause existing user code to break. Requires a minor or major release. labels Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking May cause existing user code to break. Requires a minor or major release. compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants