valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.91k stars 1.76k forks source link

Optimize struct field order to reduce memory usage #1809

Closed ksw2000 closed 4 months ago

ksw2000 commented 4 months ago
  1. Reduce RequestHeader from 368 bytes to 360 bytes
  2. Reduce Request from 816 bytes to 800 bytes
  3. Reduce Response from 432 bytes to 416 bytes
  4. Reduce Client from 312 bytes to 288 bytes
  5. Reduce HostClient from 416 bytes to 392 bytes
  6. Reduce PipelineClient from 176 bytes to 168 bytes
  7. Reduce pipelineConnClient from 216 bytes to 208 bytes
  8. Reduce Cookie from 232 bytes to 224 bytes
  9. Reduce FS from 184 bytes to 160 bytes
  10. Reduce fsHandler from 168 bytes to 160 bytes
  11. Reduce ResponseHeader from 328 bytes to 320 bytes
  12. Reduce headerScanner from 128 bytes to 120 bytes
  13. Reduce TCPDialer from 104 bytes to 96 bytes
  14. Reduce workerPool from 152 bytes to 144 bytes
erikdubbelboer commented 4 months ago

Thanks!

gaby commented 4 months ago

@erikdubbelboer I figured this was also affecting bytebufferpool, and it is. So I sent a PR for that repo. https://github.com/valyala/bytebufferpool/pull/29