Optimize encoding and decoding of Vec<T> when T is trivial#7582
Optimize encoding and decoding of Vec<T> when T is trivial#7582
Vec<T> when T is trivial#7582Conversation
PR SummaryHigh Risk Overview Adjusts coverage and fixtures for the new behavior. Removes the older Written by Cursor Bugbot for commit eb09491. This will update automatically on new commits. Configure here. |
|
👍 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| let encoded_decoded: Vec<u64> = abi_decode(encoded_as_alias); | ||
| assert_eq(encoded_decoded, vec); | ||
|
|
||
| log(encoded_decoded); |
There was a problem hiding this comment.
Test vec_non_trivial incorrectly tests trivial path instead
Medium Severity
The vec_non_trivial test calls create_vec_trivial(10) and uses Vec<u64>, making it an exact duplicate of vec_trivial. It was clearly intended to call create_vec_non_trivial(10) and use Vec<u32> (the non-trivial type, since u32 has is_encode_trivial() -> false). This means the non-trivial encoding/decoding path for flat Vec<u32> has no unit test coverage. Compare with nested_vec_non_trivial which correctly uses create_nested_vec_non_trivial and Vec<Vec<u32>>.
| category = "run" | ||
|
|
||
| script_data_new_encoding = "0000000000000003000000000000007c000000000000007c000000000000007c 00000000000000030000007c0000007c0000007c" | ||
| expected_result_new_encoding = { action = "return_data", value = "0000000000000006000000000000007c000000000000007c000000000000007c000000000000007c000000000000007c000000000000007c 00000000000000060000007c0000007c0000007c0000007c0000007c0000007c" } |
There was a problem hiding this comment.
Script test data incompatible with new trivial encoding format
High Severity
The script_data_new_encoding encodes Vec<u64> with an element-count length prefix (0000000000000003 = 3), but the new trivial decode path uses raw_slice::abi_decode which interprets the prefix as a byte count. For 3 u64 elements the byte count needs to be 24 (0x18). Reading only 3 bytes produces a Vec with len = 3/8 = 0, causing the assert_eq(trivial.len(), 3) in main to fail. The expected_result_new_encoding has the same mismatch (uses 6 instead of 48).


Description
This PR optimizes the encoding and decoding of
std::vec::Vec::<T>whenTis a trivially encodable and decodable type. In that case, we don't have encode each element individually, but just encode the vector's length and mem-copy its content to theBuffer.Checklist
Breaking*orNew Featurelabels where relevant.