Skip to content

refactor: store RSV bits more efficiently#38

Merged
mccutchen merged 1 commit intomainfrom
rsv
Feb 4, 2025
Merged

refactor: store RSV bits more efficiently#38
mccutchen merged 1 commit intomainfrom
rsv

Conversation

@mccutchen
Copy link
Owner

@mccutchen mccutchen commented Feb 2, 2025

Storing a single byte rather than three boolean values should be more efficient, especially since (for now) we only need to test whether any RSV bit is set, and now that can happen in a single comparison.


Side note: I asked claude.ai whether this was actually more efficient, and it confidently answered incorrectly that the go compiler would optimizes 3 neighboring bools in a struct, before correcting itself and providing a test program when asked for a reference.

🖼️ claud.ai transcript screenshot (because they don't allow sharing transcripts for some reason?) image

Too lazy to compare with ChatGPT or DeepSeek or whatever.

@mccutchen mccutchen changed the title refactor: store RSV bites more efficiently refactor: store RSV bytes more efficiently Feb 2, 2025
@github-actions
Copy link

github-actions bot commented Feb 2, 2025

🔥 Run benchmarks comparing 872ca70 against main:

gh workflow run bench.yaml -f pr_number=38

Note: this comment will update with each new commit.

@mccutchen mccutchen changed the title refactor: store RSV bytes more efficiently refactor: store RSV bits more efficiently Feb 2, 2025
@codecov
Copy link

codecov bot commented Feb 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.44%. Comparing base (a558272) to head (872ca70).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   88.56%   92.44%   +3.88%     
==========================================
  Files           3        3              
  Lines         446      437       -9     
==========================================
+ Hits          395      404       +9     
+ Misses         38       26      -12     
+ Partials       13        7       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link

github-actions bot commented Feb 4, 2025

benchstats: a558272...872ca70

View full benchmark output on the workflow summary.

goos: linux
goarch: amd64
pkg: github.com/mccutchen/websocket
cpu: AMD EPYC 7763 64-Core Processor                
                       │ ./baseline/bench-results.txt │       ./head/bench-results.txt       │
                       │            sec/op            │    sec/op     vs base                │
ReadFrame/1KiB-4                          1.095µ ± 0%   1.049µ ±  2%   -4.25% (p=0.000 n=10)
ReadFrame/1MiB-4                         1011.6µ ± 1%   955.0µ ±  1%   -5.59% (p=0.000 n=10)
ReadFrame/8MiB-4                          7.920m ± 1%   7.353m ±  1%   -7.17% (p=0.000 n=10)
ReadFrame/16MiB-4                         15.72m ± 1%   14.73m ±  1%   -6.28% (p=0.000 n=10)
ReadMessage/1KiB/1-4                      1.760µ ± 1%   1.753µ ±  0%   -0.43% (p=0.017 n=10)
ReadMessage/8MiB/1-4                      8.704m ± 1%   8.089m ±  1%   -7.06% (p=0.000 n=10)
ReadMessage/16MiB/1-4                     17.18m ± 1%   15.98m ±  2%   -6.99% (p=0.000 n=10)
ReadMessage/1KiB/4-4                      3.061µ ± 1%   2.997µ ±  0%   -2.07% (p=0.000 n=10)
ReadMessage/8MiB/4-4                      12.13m ± 5%   10.98m ±  6%   -9.51% (p=0.000 n=10)
ReadMessage/16MiB/4-4                     21.78m ± 2%   21.80m ±  5%        ~ (p=0.971 n=10)
ReadMessage/1KiB/16-4                     5.226µ ± 0%   4.892µ ±  2%   -6.40% (p=0.000 n=10)
ReadMessage/8MiB/16-4                     17.13m ± 6%   17.59m ± 11%        ~ (p=0.218 n=10)
ReadMessage/16MiB/16-4                    28.11m ± 5%   23.18m ±  5%  -17.54% (p=0.000 n=10)
geomean                                   818.4µ        773.0µ         -5.55%

                       │ ./baseline/bench-results.txt │       ./head/bench-results.txt        │
                       │             B/op             │     B/op      vs base                 │
ReadFrame/1KiB-4                         1.055Ki ± 0%   1.055Ki ± 0%       ~ (p=1.000 n=10) ¹
ReadFrame/1MiB-4                         1.000Mi ± 0%   1.000Mi ± 0%       ~ (p=0.510 n=10)
ReadFrame/8MiB-4                         8.000Mi ± 0%   8.000Mi ± 0%       ~ (p=0.100 n=10)
ReadFrame/16MiB-4                        16.00Mi ± 0%   16.00Mi ± 0%       ~ (p=0.124 n=10)
ReadMessage/1KiB/1-4                     1.086Ki ± 0%   1.086Ki ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/8MiB/1-4                     8.000Mi ± 0%   8.000Mi ± 0%       ~ (p=0.641 n=10)
ReadMessage/16MiB/1-4                    16.00Mi ± 0%   16.00Mi ± 0%       ~ (p=0.671 n=10)
ReadMessage/1KiB/4-4                     4.000Ki ± 0%   4.000Ki ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/8MiB/4-4                     28.57Mi ± 0%   28.57Mi ± 0%  -0.00% (p=0.043 n=10)
ReadMessage/16MiB/4-4                    57.09Mi ± 0%   57.09Mi ± 0%       ~ (p=0.128 n=10)
ReadMessage/1KiB/16-4                    5.031Ki ± 0%   5.031Ki ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/8MiB/16-4                    47.22Mi ± 0%   47.22Mi ± 0%       ~ (p=0.699 n=10)
ReadMessage/16MiB/16-4                   93.81Mi ± 0%   93.81Mi ± 0%       ~ (p=0.423 n=10)
geomean                                  1.072Mi        1.072Mi       +0.00%
¹ all samples are equal

                       │ ./baseline/bench-results.txt │      ./head/bench-results.txt       │
                       │          allocs/op           │ allocs/op   vs base                 │
ReadFrame/1KiB-4                           5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
ReadFrame/1MiB-4                           5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
ReadFrame/8MiB-4                           5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
ReadFrame/16MiB-4                          5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/1KiB/1-4                       6.000 ± 0%   6.000 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/8MiB/1-4                       6.000 ± 0%   6.000 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/16MiB/1-4                      6.000 ± 0%   6.000 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/1KiB/4-4                       24.00 ± 0%   24.00 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/8MiB/4-4                       24.00 ± 0%   24.00 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/16MiB/4-4                      24.00 ± 0%   24.00 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/1KiB/16-4                      70.00 ± 0%   70.00 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/8MiB/16-4                      90.00 ± 0%   90.00 ± 0%       ~ (p=1.000 n=10) ¹
ReadMessage/16MiB/16-4                     90.00 ± 0%   90.00 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                    14.31        14.31       +0.00%
¹ all samples are equal

@mccutchen mccutchen merged commit ef31006 into main Feb 4, 2025
9 checks passed
@mccutchen mccutchen deleted the rsv branch February 4, 2025 04:43
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.

1 participant