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

Reduce the size of the Cookie by 32 bytes. #1866

Merged
merged 1 commit into from
Sep 21, 2024

Conversation

ksw2000
Copy link
Contributor

@ksw2000 ksw2000 commented Sep 14, 2024

Replace the field bufKV with two []byte fields and remove the filed buf.

  • Reduce Cookie from 224 to 192 bytes.
  • In the benchmark tests, although there is no significant performance improvement, it theoretically reduces memory usage by 14.3%.
type Cookie struct {
-       buf    []byte    // -24 bytes
-       bufKV  argsKV    // -56 bytes
+       bufK   []byte    // +24 bytes
+       bufV   []byte    // +24 bytes
}

In the benchmark test, the execution time increased slightly by about 1%.

goos: linux
goarch: amd64
pkg: github.com/valyala/fasthttp
cpu: AMD EPYC 7763 64-Core Processor                
                       │   old.txt   │              new2.txt              │
                       │   sec/op    │   sec/op     vs base               │
CookieParseMin-4         26.55n ± 1%   26.53n ± 1%       ~ (p=0.733 n=20)
CookieParseNoExpires-4   89.89n ± 3%   91.65n ± 3%  +1.96% (p=0.033 n=20)
CookieParseFull-4        531.0n ± 3%   540.8n ± 1%       ~ (p=0.057 n=20)
geomean                  108.2n        109.6n       +1.24%

                       │   old.txt    │              new2.txt               │
                       │     B/op     │    B/op     vs base                 │
CookieParseMin-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20) ¹
CookieParseNoExpires-4   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20) ¹
CookieParseFull-4        163.0 ± 0%     163.0 ± 0%       ~ (p=1.000 n=20) ¹
geomean                             ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                       │   old.txt    │              new2.txt               │
                       │  allocs/op   │ allocs/op   vs base                 │
CookieParseMin-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20) ¹
CookieParseNoExpires-4   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20) ¹
CookieParseFull-4        4.000 ± 0%     4.000 ± 0%       ~ (p=1.000 n=20) ¹
geomean                             ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

Replace the field `bufKV` with two `[]byte` fields and remove the filed `buf`.

- Reduce Cookie from **224** to **192** bytes.
- In the benchmark tests, although there is no significant performance improvement, it theoretically reduces memory usage by **14.3%**.
@ksw2000 ksw2000 marked this pull request as ready for review September 14, 2024 08:12
@erikdubbelboer erikdubbelboer merged commit 318e68e into valyala:master Sep 21, 2024
15 checks passed
@erikdubbelboer
Copy link
Collaborator

Thanks!

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.

2 participants