Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add to_slice #461

Merged
merged 1 commit into from
Jul 22, 2024
Merged

Add to_slice #461

merged 1 commit into from
Jul 22, 2024

Conversation

wcampbell0x2a
Copy link
Collaborator

No description provided.

Copy link

Benchmark for f979437

Click to view benchmark
Test Base PR %
deku_read_bits 1241.4±14.49ns 1243.0±23.13ns +0.13%
deku_read_byte 3.3±0.05ns 3.3±0.06ns 0.00%
deku_read_enum 2.6±0.05ns 2.6±0.06ns 0.00%
deku_read_vec 33.7±0.60ns 34.2±0.52ns +1.48%
deku_write_bits 160.6±6.37ns 167.4±7.29ns +4.23%
deku_write_byte 22.4±0.33ns 22.6±0.93ns +0.89%
deku_write_enum 21.4±0.31ns 21.4±0.52ns 0.00%
deku_write_vec 336.0±6.40ns 394.1±5.06ns +17.29%

src/lib.rs Outdated
Comment on lines 538 to 540
DekuWriter::to_writer(self, &mut __deku_writer, ()).unwrap();
__deku_writer.finalize().unwrap();

Choose a reason for hiding this comment

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

Is it okay to use unwrap() here? to_bytes is using ? to propagate the errors to the caller.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed from unwrap

@wcampbell0x2a wcampbell0x2a force-pushed the add-to-slice branch 2 times, most recently from 359ab28 to b0d662a Compare July 18, 2024 01:58
Copy link

Benchmark for 5be88f4

Click to view benchmark
Test Base PR %
deku_read_bits 1232.4±11.28ns 1277.5±18.10ns +3.66%
deku_read_byte 3.3±0.04ns 3.3±0.03ns 0.00%
deku_read_enum 2.5±0.05ns 2.5±0.05ns 0.00%
deku_read_vec 32.9±0.22ns 33.1±0.99ns +0.61%
deku_write_bits 169.3±3.27ns 166.5±5.88ns -1.65%
deku_write_byte 22.6±0.34ns 22.4±0.33ns -0.88%
deku_write_enum 21.1±0.31ns 21.1±0.41ns 0.00%
deku_write_vec 336.1±10.29ns 349.7±6.62ns +4.05%

Copy link

Benchmark for 15f0828

Click to view benchmark
Test Base PR %
deku_read_bits 1264.6±14.00ns 1262.6±20.41ns -0.16%
deku_read_byte 3.4±0.40ns 3.5±0.08ns +2.94%
deku_read_enum 2.5±0.08ns 2.8±0.08ns +12.00%
deku_read_vec 34.1±0.83ns 34.6±0.69ns +1.47%
deku_write_bits 170.1±3.31ns 170.7±3.74ns +0.35%
deku_write_byte 22.4±0.19ns 22.5±0.32ns +0.45%
deku_write_enum 21.1±0.35ns 21.1±0.34ns 0.00%
deku_write_vec 345.7±6.75ns 386.5±5.88ns +11.80%

DekuWriter::to_writer(self, &mut __deku_writer, ())?;
__deku_writer.finalize()?;

Ok(__deku_writer.bits_written / 8)

Choose a reason for hiding this comment

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

There might be a corner case here. Would it handle the following case?

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[deku(endian = "big")]
struct DekuTest {
    #[deku(bits = 4)]
    field_a: u8,
    field_b: u8,
}

Let's say serializing this struct results in bits_written = 12 which means we need two bytes to store them into. But bits_written / 8 = 1. So I'm thinking either (bit_written + 8) / 8 or ceil() would be right way. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The above finalize call will fill in bits until it hits the byte boundary to make sure everything is written. This follows the logic of to_bytes.

Copy link
Owner

@sharksforarms sharksforarms left a comment

Choose a reason for hiding this comment

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

Thanks!

@wcampbell0x2a wcampbell0x2a merged commit 563396d into master Jul 22, 2024
9 of 13 checks passed
@wcampbell0x2a wcampbell0x2a deleted the add-to-slice branch July 22, 2024 14:54
wcampbell0x2a added a commit that referenced this pull request Sep 4, 2024
wcampbell0x2a added a commit that referenced this pull request Sep 4, 2024
@wcampbell0x2a wcampbell0x2a mentioned this pull request Sep 6, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants