Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Seek first bytes lengths before seek bits for __deku_input #502

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

wcampbell0x2a
Copy link
Collaborator

  • For bits input into from_bytes, first seek the byte amount until we can seek the bits amount

Closes #500

Copy link

github-actions bot commented Nov 2, 2024

Benchmark for 78ed86b

Click to view benchmark
Test Base PR %
count_from_u8_specialize 94.1±1.10ns 91.6±1.03ns -2.66%
count_no_specialize 2.7±0.02µs 2.4±0.02µs -11.11%
count_specialize 103.7±1.63ns 100.9±1.30ns -2.70%
deku_read_bits 1183.8±17.13ns 1187.4±20.18ns +0.30%
deku_read_byte 4.5±0.05ns 4.2±0.05ns -6.67%
deku_read_enum 3.8±0.06ns 3.6±0.07ns -5.26%
deku_read_vec 30.2±0.73ns 30.3±1.27ns +0.33%
deku_write_bits 186.9±6.34ns 183.1±6.44ns -2.03%
deku_write_byte 26.3±1.37ns 26.1±0.48ns -0.76%
deku_write_enum 23.8±0.14ns 23.9±0.23ns +0.42%
deku_write_vec 452.7±7.42ns 433.7±7.10ns -4.20%
read_all 5.0±0.04µs 5.0±0.04µs 0.00%
read_all_bytes 4.2±0.05µs 5.0±0.08µs +19.05%

if bytes != 0 {
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_reader.seek(SeekFrom::Current(i64::try_from(bytes).unwrap())) {
Copy link
Owner

Choose a reason for hiding this comment

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

should we handle the error from i64::try_from? else we should expect instead of unwrap

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yah, the seek_* code has the same problem.

if bytes != 0 {
use ::#crate_::no_std_io::Seek;
use ::#crate_::no_std_io::SeekFrom;
if let Err(e) = __deku_reader.seek(SeekFrom::Current(i64::try_from(bytes).unwrap())) {
Copy link
Owner

@sharksforarms sharksforarms Nov 2, 2024

Choose a reason for hiding this comment

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

same here (edit: and a couple more spots in the code)

@@ -121,9 +131,19 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
use ::#crate_::DekuReader as _;
let mut __deku_cursor = #crate_::no_std_io::Cursor::new(__deku_input.0);
let mut __deku_reader = &mut deku::reader::Reader::new(&mut __deku_cursor);
if __deku_input.1 != 0 {
__deku_reader.skip_bits(__deku_input.1)?;
let bytes = __deku_input.1 / 8;
Copy link
Owner

Choose a reason for hiding this comment

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

I see this section is being repeated, worth having an emit_.. function for this new chunk?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking that also, it's weird to codegen this code over and over again instead of something in the reader.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, I forgot skip_bits was already only used for this.

sharksforarms
sharksforarms previously approved these changes Nov 2, 2024
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.

ty!

* For bits input into from_bytes, first seek the byte amount until we can
 seek the bits amount

Closes #500
Copy link

github-actions bot commented Nov 2, 2024

Benchmark for ba10dc8

Click to view benchmark
Test Base PR %
count_from_u8_specialize 98.2±1.28ns 97.0±0.87ns -1.22%
count_no_specialize 2.7±0.03µs 2.4±0.03µs -11.11%
count_specialize 97.8±1.63ns 95.2±1.25ns -2.66%
deku_read_bits 1189.0±16.66ns 1195.0±14.52ns +0.50%
deku_read_byte 4.5±0.05ns 4.1±0.11ns -8.89%
deku_read_enum 3.8±0.07ns 3.3±0.09ns -13.16%
deku_read_vec 30.2±0.69ns 30.5±0.46ns +0.99%
deku_write_bits 195.9±6.15ns 206.6±5.17ns +5.46%
deku_write_byte 26.1±0.34ns 26.1±0.55ns 0.00%
deku_write_enum 24.0±0.97ns 24.0±0.73ns 0.00%
deku_write_vec 423.6±7.28ns 440.4±8.71ns +3.97%
read_all 5.0±0.04µs 4.2±0.06µs -16.00%
read_all_bytes 4.2±0.06µs 4.3±0.23µs +2.38%

Copy link

github-actions bot commented Nov 2, 2024

Benchmark for 6d8d88a

Click to view benchmark
Test Base PR %
count_from_u8_specialize 95.9±0.89ns 97.8±1.36ns +1.98%
count_no_specialize 2.6±0.02µs 2.4±0.04µs -7.69%
count_specialize 101.9±1.17ns 94.4±1.16ns -7.36%
deku_read_bits 1185.7±18.02ns 1204.2±12.96ns +1.56%
deku_read_byte 4.5±0.02ns 4.2±0.06ns -6.67%
deku_read_enum 3.8±0.05ns 3.6±0.04ns -5.26%
deku_read_vec 30.3±1.65ns 30.5±0.60ns +0.66%
deku_write_bits 194.1±14.89ns 191.2±8.14ns -1.49%
deku_write_byte 26.1±0.43ns 26.0±0.19ns -0.38%
deku_write_enum 23.9±0.34ns 23.9±0.40ns 0.00%
deku_write_vec 425.0±7.46ns 441.7±7.97ns +3.93%
read_all 5.0±0.06µs 5.0±0.05µs 0.00%
read_all_bytes 4.2±0.08µs 5.1±0.15µs +21.43%

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.

nice!

@wcampbell0x2a wcampbell0x2a merged commit 2b24a56 into master Nov 5, 2024
13 of 15 checks passed
@wcampbell0x2a wcampbell0x2a deleted the seek-first-when-deku-input-has-bits branch November 5, 2024 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offset in from_bytes() causes panic in reader.rs if the bytes are greater than 128
2 participants