Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

dev: various optimizations #1010

Merged
merged 5 commits into from
Oct 4, 2024
Merged

dev: various optimizations #1010

merged 5 commits into from
Oct 4, 2024

Conversation

enitrat
Copy link
Contributor

@enitrat enitrat commented Oct 2, 2024

Optimizes ToBytes, FromBytes, to_u64_words

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_bytes_full (gas: ~5)
        steps: 1382
        memory holes: 53
        builtins: (range_check: 125, bitwise: 19)
        syscalls: ()

to

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_bytes_full (gas: ~2)
        steps: 442
        memory holes: 20
        builtins: (range_check: 29, bitwise: 4)
        syscalls: ()

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_le_bytes_full (gas: ~5)
        steps: 1349
        memory holes: 53
        builtins: (range_check: 117, bitwise: 19)
        syscalls: ()

to

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_le_bytes_full (gas: ~2)
        steps: 486
        memory holes: 20
        builtins: (range_check: 34, bitwise: 4)
        syscalls: ()

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_full (gas: ~11)
        steps: 2739
        memory holes: 141
        builtins: (range_check: 274, bitwise: 39)
        syscalls: ()

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_partial (gas: ~8)
        steps: 1965
        memory holes: 114
        builtins: (range_check: 193, bitwise: 27)
        syscalls: ()

to

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_partial (gas: ~8)
        steps: 1972
        memory holes: 81
        builtins: (range_check: 199, bitwise: 27)
        syscalls: ()

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_full (gas: ~12)
        steps: 2847
        memory holes: 146
        builtins: (range_check: 285, bitwise: 39)
        syscalls: ()

This change is Reviewable

@enitrat enitrat requested a review from ClementWalter as a code owner October 2, 2024 17:47
@enitrat enitrat requested a review from obatirou October 3, 2024 13:50
@@ -32,21 +32,22 @@ pub impl U8SpanExImpl of U8SpanExTrait {
/// - A usize representing the number of bytes in the last word
fn to_u64_words(self: Span<u8>) -> (Array<u64>, u64, usize) {
let nonzero_8: NonZero<u32> = 8_u32.try_into().unwrap();
let (full_u64_word_count, last_input_num_bytes) = DivRem::div_rem(self.len(), nonzero_8);
let (_, last_input_num_bytes) = DivRem::div_rem(self.len(), nonzero_8);
Copy link
Contributor

Choose a reason for hiding this comment

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


let mut u64_words: Array<u64> = Default::default();
let mut u64_words: Array<u64> = array![];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not keep default ?
More explicit to have an empty array macro ?

@enitrat enitrat force-pushed the dev/optimize-to-u64-words branch from dbab69a to 24b5f35 Compare October 3, 2024 19:02
@enitrat enitrat merged commit e1ccb18 into main Oct 4, 2024
4 of 5 checks passed
@enitrat enitrat deleted the dev/optimize-to-u64-words branch October 4, 2024 08:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants