Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove re-reading for ip_pat#540

Merged
wcampbell0x2a merged 4 commits into
masterfrom
remove-re-reading-for-id-pat
Apr 3, 2025
Merged

Remove re-reading for ip_pat#540
wcampbell0x2a merged 4 commits into
masterfrom
remove-re-reading-for-id-pat

Conversation

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator

@wcampbell0x2a wcampbell0x2a commented Mar 29, 2025

  • Use the last read value for the id instead of jumping back and re-reading that value.
  • Compare the endian, bits,and bytes amt when reading from an id. This is important when writing
    as without this check you end up with different bytes being written. More fields could
    be checked against this?
  • Reader: Remove last_bits_read_amt and seek_last_read

Should close #533

@wcampbell0x2a wcampbell0x2a force-pushed the remove-re-reading-for-id-pat branch from 478580a to ef83bed Compare March 29, 2025 15:32
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for 3b4f2d7

Click to view benchmark
Test Base PR %
count_from_u8_specialize 97.0±1.13ns 96.4±1.46ns -0.62%
count_no_specialize 2.4±0.02µs 1606.6±29.99ns -33.06%
count_specialize 97.5±1.40ns 95.1±1.12ns -2.46%
deku_read_bits 1307.0±17.61ns 1357.5±23.29ns +3.86%
deku_read_byte 5.3±0.08ns 4.4±0.05ns -16.98%
deku_read_enum 5.1±0.08ns 3.8±0.13ns -25.49%
deku_read_vec 31.1±1.08ns 30.6±0.37ns -1.61%
deku_write_bits 246.5±7.74ns 262.4±3.66ns +6.45%
deku_write_byte 23.7±0.36ns 24.0±0.31ns +1.27%
deku_write_enum 22.5±0.30ns 22.9±1.02ns +1.78%
deku_write_vec 510.4±7.02ns 489.3±6.77ns -4.13%
read_all 5.1±0.11µs 4.3±0.05µs -15.69%
read_all_bytes 5.1±0.04µs 5.1±0.04µs 0.00%

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for d741d00

Click to view benchmark
Test Base PR %
count_from_u8_specialize 94.1±3.04ns 92.5±2.72ns -1.70%
count_no_specialize 2.6±0.08µs 1585.2±37.87ns -39.03%
count_specialize 96.6±2.71ns 93.6±2.70ns -3.11%
deku_read_bits 1203.4±29.57ns 1228.5±31.28ns +2.09%
deku_read_byte 4.7±0.13ns 5.3±0.16ns +12.77%
deku_read_enum 4.2±0.11ns 3.8±0.04ns -9.52%
deku_read_vec 28.7±0.55ns 28.4±0.67ns -1.05%
deku_write_bits 218.9±4.90ns 241.8±12.32ns +10.46%
deku_write_byte 22.0±0.46ns 22.7±0.43ns +3.18%
deku_write_enum 20.8±0.39ns 21.4±1.10ns +2.88%
deku_write_vec 453.2±6.28ns 457.1±6.91ns +0.86%
read_all 4.9±0.13µs 4.9±0.17µs 0.00%
read_all_bytes 4.8±0.04µs 4.0±0.10µs -16.67%

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for f140256

Click to view benchmark
Test Base PR %
count_from_u8_specialize 91.4±0.97ns 94.5±1.40ns +3.39%
count_no_specialize 2.4±0.02µs 1710.0±28.58ns -28.75%
count_specialize 92.9±0.57ns 101.4±1.27ns +9.15%
deku_read_bits 1245.9±18.03ns 1248.9±16.52ns +0.24%
deku_read_byte 4.5±0.05ns 5.6±0.10ns +24.44%
deku_read_enum 4.1±0.06ns 4.1±0.04ns 0.00%
deku_read_vec 30.9±0.55ns 30.6±0.42ns -0.97%
deku_write_bits 246.9±4.62ns 252.2±3.80ns +2.15%
deku_write_byte 23.7±0.22ns 24.0±0.33ns +1.27%
deku_write_enum 22.5±0.45ns 22.7±0.17ns +0.89%
deku_write_vec 491.4±6.56ns 492.3±5.93ns +0.18%
read_all 4.3±0.06µs 5.1±0.04µs +18.60%
read_all_bytes 4.3±0.12µs 4.3±0.05µs 0.00%

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator Author

wcampbell0x2a commented Mar 29, 2025

Compare the bits and bytes amt when reading from an id

Actually, I wonder that maybe I just use the id (bits, bytes, endian), and expect no attributes on the id_pat id storage.

(I don't have time currently to implement this)

* Use the last read value for the id instead of jumping back and re-reading that value.
* Compare the endian, bits,and bytes amt when reading from an id. This is important when writing
  as without this check you end up with different bytes being written. More fields could
  be checked against this?
* Reader: Remove last_bits_read_amt and seek_last_read
@wcampbell0x2a wcampbell0x2a force-pushed the remove-re-reading-for-id-pat branch 2 times, most recently from 3e10b66 to 4dad0d8 Compare March 29, 2025 16:26
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for 73796ce

Click to view benchmark
Test Base PR %
count_from_u8_specialize 97.9±0.83ns 96.6±1.44ns -1.33%
count_no_specialize 2.8±0.01µs 1713.4±27.95ns -38.81%
count_specialize 97.7±1.08ns 95.9±1.50ns -1.84%
deku_read_bits 1275.1±10.27ns 1252.0±14.68ns -1.81%
deku_read_byte 4.9±0.06ns 5.6±0.03ns +14.29%
deku_read_enum 4.4±0.03ns 4.1±0.05ns -6.82%
deku_read_vec 31.0±0.53ns 30.7±0.54ns -0.97%
deku_write_bits 244.2±4.64ns 232.4±3.07ns -4.83%
deku_write_byte 23.7±0.24ns 24.2±0.68ns +2.11%
deku_write_enum 22.5±0.29ns 22.8±0.36ns +1.33%
deku_write_vec 489.2±6.84ns 500.9±5.49ns +2.39%
read_all 5.3±0.05µs 5.2±0.04µs -1.89%
read_all_bytes 5.2±0.04µs 4.3±0.09µs -17.31%

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator Author

Compare the bits and bytes amt when reading from an id

Actually, I wonder that maybe I just use the id (bits, bytes, endian), and expect no attributes on the id_pat id storage.

(I don't have time currently to implement this)

Pushed an update to do this. We could actually force that no attributes are used on the special storage.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for 9ced556

Click to view benchmark
Test Base PR %
count_from_u8_specialize 98.7±2.07ns 96.1±1.08ns -2.63%
count_no_specialize 2.8±0.02µs 1713.0±27.43ns -38.82%
count_specialize 94.6±0.74ns 95.9±1.67ns +1.37%
deku_read_bits 1266.9±9.26ns 1230.5±18.93ns -2.87%
deku_read_byte 4.9±0.05ns 5.6±0.02ns +14.29%
deku_read_enum 4.4±0.04ns 4.1±0.09ns -6.82%
deku_read_vec 31.0±0.39ns 30.6±0.37ns -1.29%
deku_write_bits 231.9±3.57ns 243.1±3.04ns +4.83%
deku_write_byte 23.7±0.26ns 24.1±0.50ns +1.69%
deku_write_enum 22.4±0.19ns 22.7±0.26ns +1.34%
deku_write_vec 488.4±5.63ns 504.5±5.14ns +3.30%
read_all 5.2±0.06µs 5.1±0.04µs -1.92%
read_all_bytes 5.1±0.04µs 4.3±0.05µs -15.69%

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator Author

Pushed updates to dis-allow any attributes for id_pat id storage.

This could be done in another mr, but the following should be checked and is not legal:

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[deku(id_type = "u8")]
enum DekuTest {
    #[deku(id_pat = "_")]
    VarDefault,
}

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for 5446aea

Click to view benchmark
Test Base PR %
count_from_u8_specialize 96.9±1.20ns 92.8±0.97ns -4.23%
count_no_specialize 2.4±0.03µs 1627.4±30.32ns -32.19%
count_specialize 99.4±1.27ns 96.6±1.22ns -2.82%
deku_read_bits 1297.5±15.40ns 1298.2±26.72ns +0.05%
deku_read_byte 5.4±0.17ns 4.4±0.06ns -18.52%
deku_read_enum 5.1±0.02ns 3.8±0.04ns -25.49%
deku_read_vec 31.0±0.37ns 30.8±1.12ns -0.65%
deku_write_bits 250.1±4.48ns 247.8±3.31ns -0.92%
deku_write_byte 23.7±0.39ns 24.4±0.45ns +2.95%
deku_write_enum 22.5±0.33ns 23.1±0.37ns +2.67%
deku_write_vec 488.7±5.36ns 509.5±7.67ns +4.26%
read_all 5.1±0.05µs 4.2±0.06µs -17.65%
read_all_bytes 5.2±0.05µs 5.0±0.04µs -3.85%

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator Author

Pushed updates to dis-allow any attributes for id_pat id storage.

This could be done in another mr, but the following should be checked and is not legal:

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[deku(id_type = "u8")]
enum DekuTest {
    #[deku(id_pat = "_")]
    VarDefault,
}

Nevermind, that wasn't that bad to fix: d4049d6

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for 8b26e69

Click to view benchmark
Test Base PR %
count_from_u8_specialize 97.6±1.17ns 94.5±1.14ns -3.18%
count_no_specialize 2.4±0.02µs 1717.3±29.02ns -28.45%
count_specialize 97.5±0.81ns 103.1±1.31ns +5.74%
deku_read_bits 1287.8±14.19ns 1295.5±10.70ns +0.60%
deku_read_byte 5.3±0.10ns 5.6±0.03ns +5.66%
deku_read_enum 5.1±0.05ns 4.1±0.05ns -19.61%
deku_read_vec 31.0±0.45ns 30.7±0.66ns -0.97%
deku_write_bits 269.0±4.83ns 242.7±4.20ns -9.78%
deku_write_byte 24.0±0.25ns 24.7±0.74ns +2.92%
deku_write_enum 22.8±0.33ns 23.4±0.34ns +2.63%
deku_write_vec 517.0±4.71ns 499.6±6.39ns -3.37%
read_all 5.0±0.04µs 5.1±0.05µs +2.00%
read_all_bytes 5.2±0.03µs 4.3±0.05µs -17.31%

@sharksforarms
Copy link
Copy Markdown
Owner

@wcampbell0x2a tag me when you'd like to get a review, also, maybe we should create a release after?

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator Author

@wcampbell0x2a tag me when you'd like to get a review, also, maybe we should create a release after?

Sure! I found one bug with this release in my crates, I'll push and update for that and make some release notes.

sharksforarms
sharksforarms previously approved these changes Apr 2, 2025
Copy link
Copy Markdown
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
Copy link
Copy Markdown
Collaborator Author

Repushed changes that should fix ci.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2025

Benchmark for b3bc007

Click to view benchmark
Test Base PR %
count_from_u8_specialize 98.9±0.58ns 96.6±0.92ns -2.33%
count_no_specialize 2.8±0.29µs 1715.5±34.18ns -38.73%
count_specialize 99.0±0.59ns 98.0±0.85ns -1.01%
deku_read_bits 1248.9±16.63ns 1286.9±24.19ns +3.04%
deku_read_byte 4.9±0.06ns 5.3±0.05ns +8.16%
deku_read_enum 4.5±0.05ns 4.1±0.05ns -8.89%
deku_read_vec 30.6±0.45ns 30.6±0.38ns 0.00%
deku_write_bits 233.4±4.32ns 244.5±2.65ns +4.76%
deku_write_byte 24.3±0.20ns 24.0±0.32ns -1.23%
deku_write_enum 22.7±0.21ns 23.1±0.22ns +1.76%
deku_write_vec 488.5±5.20ns 497.4±6.50ns +1.82%
read_all 5.1±0.04µs 5.2±0.04µs +1.96%
read_all_bytes 5.2±0.06µs 4.3±0.05µs -17.31%

@wcampbell0x2a wcampbell0x2a merged commit 92f4cdc into master Apr 3, 2025
@wcampbell0x2a wcampbell0x2a deleted the remove-re-reading-for-id-pat branch April 3, 2025 22:32
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.

Enums which have variant id_pat = "_" ignore BitSize ctx

2 participants