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

Impl writer #355

Merged
merged 9 commits into from
Apr 29, 2024
Merged

Impl writer #355

merged 9 commits into from
Apr 29, 2024

Conversation

wcampbell0x2a
Copy link
Collaborator

@wcampbell0x2a wcampbell0x2a commented Aug 18, 2023

Implement faster writing for bytes and support for Write. At the expense of some performance for only bit-wise writing.

Tested

Create Issue

  • It would be nice to specialize for &[u8] and Vec<u8> so that results directly to one invocation of writer.write_bytes(..) instead of 1 byte per len. This is only possible for Ctx = ()?

See wcampbell0x2a/deku-bench#6 (that uses #393)

@github-actions
Copy link

Benchmark for 54c55ed

Click to view benchmark
Test Base PR %
deku_read_bits 725.8±0.70ns 776.2±0.91ns +6.94%
deku_read_byte 25.7±1.32ns 25.8±0.07ns +0.39%
deku_read_enum 10.7±0.10ns 10.4±0.08ns -2.80%
deku_read_vec 71.4±0.33ns 65.3±0.13ns -8.54%
deku_write_bits 102.8±0.44ns 268.7±1.57ns +161.38%
deku_write_byte 152.4±0.59ns 37.7±0.17ns -75.26%
deku_write_enum 101.5±0.49ns 31.8±0.27ns -68.67%
deku_write_vec 4.0±0.01µs 523.4±2.79ns -86.91%

@github-actions
Copy link

Benchmark for bd28774

Click to view benchmark
Test Base PR %
deku_read_bits 937.3±50.25ns 1014.1±58.33ns +8.19%
deku_read_byte 26.7±1.59ns 30.2±3.09ns +13.11%
deku_read_enum 12.7±0.88ns 12.4±0.93ns -2.36%
deku_read_vec 75.5±4.17ns 75.1±4.56ns -0.53%
deku_write_bits 132.7±9.29ns 357.4±24.82ns +169.33%
deku_write_byte 189.2±11.39ns 41.5±2.83ns -78.07%
deku_write_enum 122.8±6.30ns 34.6±2.19ns -71.82%
deku_write_vec 4.7±0.26µs 577.2±119.10ns -87.72%

@github-actions
Copy link

Benchmark for 95f691c

Click to view benchmark
Test Base PR %
deku_read_bits 1103.8±70.05ns 1134.2±67.78ns +2.75%
deku_read_byte 31.0±1.20ns 31.5±1.67ns +1.61%
deku_read_enum 14.4±0.69ns 15.1±1.91ns +4.86%
deku_read_vec 89.4±5.26ns 88.4±5.63ns -1.12%
deku_write_bits 151.0±6.56ns 326.1±26.75ns +115.96%
deku_write_byte 219.6±22.20ns 48.9±2.14ns -77.73%
deku_write_enum 145.0±15.60ns 42.1±1.32ns -70.97%
deku_write_vec 5.4±0.31µs 692.7±31.56ns -87.17%

@github-actions
Copy link

Benchmark for ed7c8e1

Click to view benchmark
Test Base PR %
deku_read_bits 1052.9±1.05ns 1084.6±10.88ns +3.01%
deku_read_byte 31.3±0.72ns 33.0±0.50ns +5.43%
deku_read_enum 13.7±0.02ns 15.1±0.11ns +10.22%
deku_read_vec 83.3±0.45ns 83.9±0.17ns +0.72%
deku_write_bits 147.6±0.07ns 299.5±0.37ns +102.91%
deku_write_byte 202.0±1.07ns 52.0±0.29ns -74.26%
deku_write_enum 134.9±0.56ns 45.4±0.12ns -66.35%
deku_write_vec 5.1±0.02µs 591.8±0.37ns -88.40%

@github-actions
Copy link

Benchmark for 699a870

Click to view benchmark
Test Base PR %
deku_read_bits 1053.9±1.30ns 1091.9±1.35ns +3.61%
deku_read_byte 31.1±0.14ns 30.4±0.07ns -2.25%
deku_read_enum 13.8±0.03ns 15.4±0.11ns +11.59%
deku_read_vec 83.1±0.25ns 82.8±0.25ns -0.36%
deku_write_bits 147.9±0.16ns 297.7±0.29ns +101.28%
deku_write_byte 201.8±2.31ns 54.8±0.36ns -72.84%
deku_write_enum 134.6±0.58ns 46.3±0.18ns -65.60%
deku_write_vec 5.1±0.02µs 589.2±0.44ns -88.45%

@wcampbell0x2a wcampbell0x2a force-pushed the impl-reader branch 3 times, most recently from e0f8089 to 19ee687 Compare August 28, 2023 22:55
@wcampbell0x2a wcampbell0x2a force-pushed the impl-reader branch 5 times, most recently from 9e6aca1 to bf6defb Compare September 8, 2023 01:37
@github-actions
Copy link

Benchmark for 3e9011c

Click to view benchmark
Test Base PR %
deku_read_bits 779.1±0.85ns 775.2±0.50ns -0.50%
deku_read_byte 23.7±0.74ns 23.9±0.08ns +0.84%
deku_read_enum 9.9±0.07ns 10.0±0.31ns +1.01%
deku_read_vec 67.7±0.67ns 67.3±0.13ns -0.59%
deku_write_bits 109.4±0.51ns 251.6±1.02ns +129.98%
deku_write_byte 156.0±0.63ns 42.6±0.18ns -72.69%
deku_write_enum 106.9±0.90ns 35.5±0.27ns -66.79%
deku_write_vec 3.9±0.01µs 622.0±9.60ns -84.05%

@github-actions
Copy link

Benchmark for eb2f763

Click to view benchmark
Test Base PR %
deku_read_bits 893.0±0.58ns 904.3±2.09ns +1.27%
deku_read_byte 23.0±0.16ns 24.8±0.18ns +7.83%
deku_read_enum 11.2±0.07ns 11.1±0.09ns -0.89%
deku_read_vec 68.7±0.14ns 68.8±0.19ns +0.15%
deku_write_bits 127.4±0.09ns 251.1±1.50ns +97.10%
deku_write_byte 182.2±1.07ns 43.6±0.28ns -76.07%
deku_write_enum 119.2±0.48ns 37.6±0.13ns -68.46%
deku_write_vec 4.6±0.00µs 507.2±2.27ns -88.97%

@github-actions
Copy link

Benchmark for 91bbf94

Click to view benchmark
Test Base PR %
deku_read_bits 832.6±36.62ns 860.2±48.40ns +3.31%
deku_read_byte 21.6±0.98ns 24.4±1.15ns +12.96%
deku_read_enum 11.3±0.56ns 10.5±0.68ns -7.08%
deku_read_vec 64.3±2.52ns 64.9±2.73ns +0.93%
deku_write_bits 118.8±6.93ns 231.4±16.04ns +94.78%
deku_write_byte 172.5±8.25ns 43.0±2.28ns -75.07%
deku_write_enum 113.4±6.13ns 36.8±1.66ns -67.55%
deku_write_vec 4.3±0.22µs 441.7±16.68ns -89.73%

@github-actions
Copy link

Benchmark for 28f76c8

Click to view benchmark
Test Base PR %
deku_read_bits 776.4±1.38ns 781.3±0.62ns +0.63%
deku_read_byte 24.0±0.44ns 25.6±0.11ns +6.67%
deku_read_enum 10.1±0.09ns 10.2±0.08ns +0.99%
deku_read_vec 67.5±0.30ns 67.8±0.21ns +0.44%
deku_write_bits 106.5±0.44ns 228.2±7.17ns +114.27%
deku_write_byte 165.0±1.08ns 40.8±0.19ns -75.27%
deku_write_enum 105.7±0.46ns 35.2±0.64ns -66.70%
deku_write_vec 4.0±0.01µs 509.7±7.92ns -87.26%

@github-actions
Copy link

Benchmark for ada4d93

Click to view benchmark
Test Base PR %
deku_read_bits 1872.6±125.63ns 1867.9±79.36ns -0.25%
deku_read_byte 26.6±1.25ns 26.2±0.95ns -1.50%
deku_read_enum 12.4±0.78ns 12.1±0.49ns -2.42%
deku_read_vec 73.6±2.35ns 76.2±5.11ns +3.53%
deku_write_bits 175.5±7.25ns 319.2±14.09ns +81.88%
deku_write_byte 193.4±5.91ns 43.7±1.28ns -77.40%
deku_write_enum 131.1±5.37ns 37.9±1.17ns -71.09%
deku_write_vec 4.5±0.26µs 532.5±23.09ns -88.17%

@github-actions
Copy link

Benchmark for 64901e4

Click to view benchmark
Test Base PR %
deku_read_bits 1404.3±1.14ns 1402.9±7.37ns -0.10%
deku_read_byte 25.4±0.22ns 25.9±0.11ns +1.97%
deku_read_enum 9.8±0.06ns 10.2±0.10ns +4.08%
deku_read_vec 66.0±0.28ns 70.3±0.36ns +6.52%
deku_write_bits 140.3±0.31ns 250.0±0.48ns +78.19%
deku_write_byte 158.0±0.58ns 40.7±0.17ns -74.24%
deku_write_enum 105.4±0.51ns 34.5±0.17ns -67.27%
deku_write_vec 3.9±0.01µs 415.1±1.76ns -89.36%

@github-actions
Copy link

Benchmark for b1956c2

Click to view benchmark
Test Base PR %
deku_read_bits 2.0±0.01µs 2.0±0.02µs 0.00%
deku_read_byte 33.0±1.97ns 30.3±0.14ns -8.18%
deku_read_enum 13.4±0.13ns 25.5±0.05ns +90.30%
deku_read_vec 83.3±3.20ns 81.3±0.32ns -2.40%
deku_write_bits 193.8±1.25ns 350.4±0.45ns +80.80%
deku_write_byte 207.3±1.13ns 53.6±0.47ns -74.14%
deku_write_enum 140.2±1.08ns 48.2±0.64ns -65.62%
deku_write_vec 5.3±0.02µs 448.2±0.53ns -91.54%

@github-actions
Copy link

Benchmark for f60fb68

Click to view benchmark
Test Base PR %
deku_read_bits 2.2±0.10µs 2.3±0.16µs +4.55%
deku_read_byte 32.5±1.91ns 32.7±1.48ns +0.62%
deku_read_enum 14.4±0.89ns 14.8±1.17ns +2.78%
deku_read_vec 88.3±7.06ns 93.8±6.03ns +6.23%
deku_write_bits 214.6±11.27ns 401.0±16.73ns +86.86%
deku_write_byte 242.0±15.10ns 52.9±1.98ns -78.14%
deku_write_enum 157.1±5.69ns 46.6±3.62ns -70.34%
deku_write_vec 5.6±0.35µs 526.2±27.53ns -90.60%

Copy link

Benchmark for aa9c730

Click to view benchmark
Test Base PR %
deku_read_bits 1187.2±11.38ns 1297.4±17.88ns +9.28%
deku_read_byte 21.7±0.24ns 21.6±0.34ns -0.46%
deku_read_enum 9.3±0.16ns 9.6±0.65ns +3.23%
deku_read_vec 57.7±0.75ns 58.6±0.89ns +1.56%
deku_write_bits 128.4±1.16ns 209.9±3.56ns +63.47%
deku_write_byte 136.4±4.24ns 36.5±1.56ns -73.24%
deku_write_enum 92.3±5.37ns 30.7±0.33ns -66.74%
deku_write_vec 3.2±0.15µs 276.4±3.20ns -91.36%

@sharksforarms
Copy link
Owner

@wcampbell0x2a ack. I may not get to review it until the new year

@wcampbell0x2a
Copy link
Collaborator Author

Butterfingers closing the mr 😂

No problem! I also might bike-shed the names back to read and write instead of to_writer. Idk.

Copy link

Benchmark for e323734

Click to view benchmark
Test Base PR %
deku_read_bits 1213.5±37.96ns 1226.0±16.02ns +1.03%
deku_read_byte 21.1±0.45ns 21.1±0.53ns 0.00%
deku_read_enum 9.6±0.15ns 9.5±0.14ns -1.04%
deku_read_vec 58.2±0.44ns 59.1±0.43ns +1.55%
deku_write_bits 125.9±4.66ns 194.4±2.03ns +54.41%
deku_write_byte 130.4±6.15ns 21.5±0.41ns -83.51%
deku_write_enum 90.7±5.51ns 20.6±1.35ns -77.29%
deku_write_vec 3.1±0.07µs 293.2±7.28ns -90.54%

Copy link

Benchmark for 47f4940

Click to view benchmark
Test Base PR %
deku_read_bits 1102.4±10.87ns 1212.6±30.33ns +10.00%
deku_read_byte 19.3±0.35ns 20.1±0.28ns +4.15%
deku_read_enum 9.4±0.13ns 9.5±0.16ns +1.06%
deku_read_vec 54.1±1.11ns 54.0±0.75ns -0.18%
deku_write_bits 113.4±1.58ns 179.5±3.53ns +58.29%
deku_write_byte 124.3±2.85ns 21.3±0.33ns -82.86%
deku_write_enum 86.3±5.15ns 20.2±0.31ns -76.59%
deku_write_vec 3.0±0.05µs 264.1±1.73ns -91.20%

Copy link

Benchmark for 17ab8fc

Click to view benchmark
Test Base PR %
deku_read_bits 1168.8±9.71ns 1245.5±18.43ns +6.56%
deku_read_byte 18.9±0.39ns 20.2±0.59ns +6.88%
deku_read_enum 9.3±0.17ns 9.4±0.17ns +1.08%
deku_read_vec 53.3±0.33ns 53.3±0.53ns 0.00%
deku_write_bits 112.1±1.18ns 187.7±4.28ns +67.44%
deku_write_byte 125.3±3.64ns 21.2±0.39ns -83.08%
deku_write_enum 89.4±5.12ns 20.2±0.41ns -77.40%
deku_write_vec 5.0±0.03µs 299.5±1.11ns -94.01%

Copy link

Benchmark for 8ff18c4

Click to view benchmark
Test Base PR %
deku_read_bits 1203.8±18.27ns 1106.5±16.74ns -8.08%
deku_read_byte 23.1±0.84ns 22.0±0.48ns -4.76%
deku_read_enum 9.3±0.15ns 9.3±0.15ns 0.00%
deku_read_vec 53.6±0.81ns 53.6±0.79ns 0.00%
deku_write_bits 109.0±1.89ns 188.8±17.81ns +73.21%
deku_write_byte 126.4±3.24ns 20.8±0.21ns -83.54%
deku_write_enum 84.6±2.62ns 20.2±0.33ns -76.12%
deku_write_vec 3.0±0.07µs 265.0±28.27ns -91.17%

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.

This looks fantastic! I left a couple of minor comments/questions. Very exciting for this to land with the reader changes + performance improvements, thanks for your persistent efforts here

src/impls/boxed.rs Show resolved Hide resolved
src/impls/boxed.rs Outdated Show resolved Hide resolved
src/impls/slice.rs Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 7, 2024

Benchmark for 6ce10f9

Click to view benchmark
Test Base PR %
deku_read_bits 1227.7±8.75ns 1146.8±18.09ns -6.59%
deku_read_byte 23.0±0.36ns 22.1±0.47ns -3.91%
deku_read_enum 9.3±0.13ns 9.4±0.23ns +1.08%
deku_read_vec 53.4±0.82ns 53.5±0.65ns +0.19%
deku_write_bits 108.9±1.77ns 181.5±4.34ns +66.67%
deku_write_byte 121.7±2.30ns 20.6±0.32ns -83.07%
deku_write_enum 86.6±10.19ns 19.6±0.45ns -77.37%
deku_write_vec 3.0±0.04µs 298.2±3.66ns -90.06%

Copy link

github-actions bot commented Jan 7, 2024

Benchmark for 3d39323

Click to view benchmark
Test Base PR %
deku_read_bits 1184.4±12.63ns 1150.3±11.76ns -2.88%
deku_read_byte 23.0±0.27ns 22.1±0.33ns -3.91%
deku_read_enum 9.3±0.15ns 9.4±0.15ns +1.08%
deku_read_vec 53.5±0.67ns 53.2±0.54ns -0.56%
deku_write_bits 113.1±4.14ns 199.1±4.26ns +76.04%
deku_write_byte 121.4±2.36ns 20.6±0.20ns -83.03%
deku_write_enum 85.3±3.76ns 19.4±0.39ns -77.26%
deku_write_vec 3.1±0.04µs 304.6±5.71ns -90.17%

Copy link

github-actions bot commented Jan 7, 2024

Benchmark for 4a4679c

Click to view benchmark
Test Base PR %
deku_read_bits 1198.8±11.17ns 1079.3±20.78ns -9.97%
deku_read_byte 22.8±0.70ns 21.5±0.34ns -5.70%
deku_read_enum 9.3±0.13ns 9.4±0.13ns +1.08%
deku_read_vec 53.3±0.63ns 53.4±0.74ns +0.19%
deku_write_bits 108.6±1.51ns 197.9±5.05ns +82.23%
deku_write_byte 122.3±3.46ns 20.5±0.36ns -83.24%
deku_write_enum 85.4±3.41ns 19.2±0.34ns -77.52%
deku_write_vec 3.0±0.04µs 300.5±3.91ns -89.98%

wcampbell0x2a and others added 9 commits April 5, 2024 19:48
* Update to syn 2.0, darling 0.20

- Change `type` for enums into `id_type`, as this is no longer
accepted through the syn parser library

* Update to rstest 0.18
- Reduce codegen by making this a default impl
Copy link

github-actions bot commented Apr 6, 2024

Benchmark for 6633da3

Click to view benchmark
Test Base PR %
deku_read_bits 1242.5±24.81ns 1160.3±18.15ns -6.62%
deku_read_byte 20.3±0.51ns 20.9±0.64ns +2.96%
deku_read_enum 9.3±0.08ns 9.4±0.17ns +1.08%
deku_read_vec 59.2±0.58ns 58.1±0.59ns -1.86%
deku_write_bits 122.8±6.65ns 191.6±6.69ns +56.03%
deku_write_byte 122.3±3.33ns 21.1±0.37ns -82.75%
deku_write_enum 87.3±3.93ns 20.5±0.19ns -76.52%
deku_write_vec 3.0±0.06µs 281.1±3.14ns -90.63%

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.

Sorry for the delay, this looks great.

@wcampbell0x2a wcampbell0x2a merged commit 79ca046 into master Apr 29, 2024
14 of 15 checks passed
@wcampbell0x2a wcampbell0x2a deleted the impl-writer branch April 29, 2024 22:03
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.

3 participants