prometheus/util
jub0bs 329ec6831a
util/httputil: reduce heap allocations in newCompressedResponseWriter (#16001)
* util/httputil: Benchmark newCompressedResponseWriter

This benchmark illustrates that newCompressedResponseWriter incurs a
prohibitive amount of heap allocations when handling a request containing a
malicious Accept-Encoding header.¬

Signed-off-by: jub0bs <jcretel-infosec+github@protonmail.com>

* util/httputil: Improve newCompressedResponseWriter

This change dramatically reduces the heap allocations (in bytes)
incurred when handling a request containing a malicious Accept-Encoding header.

Below are some benchmark results; for conciseness, I've omitted the name of the
benchmark function (BenchmarkNewCompressionHandler_MaliciousAcceptEncoding):

```
goos: darwin
goarch: amd64
pkg: github.com/prometheus/prometheus/util/httputil
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
│     old     │                 new                 │
│   sec/op    │   sec/op     vs base                │
  18.60m ± 2%   13.54m ± 3%  -27.17% (p=0.000 n=10)

│       old        │                 new                 │
│       B/op       │    B/op     vs base                 │
  16785442.50 ± 0%   32.00 ± 0%  -100.00% (p=0.000 n=10)

│    old     │                new                 │
│ allocs/op  │ allocs/op   vs base                │
  2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
```

Signed-off-by: jub0bs <jcretel-infosec+github@protonmail.com>

---------

Signed-off-by: jub0bs <jcretel-infosec+github@protonmail.com>
2025-02-11 14:14:55 +01:00
..
almost [COMMENT] Improve comment on almost.Equal; add tests 2024-08-30 10:13:00 +01:00
annotations [FIX] PromQL: Updates annotation for bin op between incompatible histograms (#15895) 2025-02-01 22:57:29 +01:00
convertnhcb Set hasCount after setting count to be consistent 2024-11-26 13:56:22 +01:00
documentcli Add support for multiple listening addresses 2024-08-20 13:09:16 +02:00
fmtutil chore: Fix typos (#14868) 2024-09-10 22:32:03 +02:00
gate
httputil util/httputil: reduce heap allocations in newCompressedResponseWriter (#16001) 2025-02-11 14:14:55 +01:00
jsonutil
junitxml promtool: JUnit-Format XML Test Results (#14506) 2024-07-29 21:28:08 +10:00
logging Merge pull request #15472 from tjhop/ref/jsonfilelogger-slog-handler 2025-01-27 20:17:46 +01:00
netconnlimit Add support for multiple listening addresses 2024-08-20 13:09:16 +02:00
notifications Move notifications in utils 2024-10-04 10:11:56 +02:00
osutil
pool
runtime chore: Fix typos (#14868) 2024-09-10 22:32:03 +02:00
runutil Append Created Timestamps (#12733) 2023-12-11 08:43:42 +00:00
stats Move from golang.org/x/exp/slices into slices now that we only support Go >= 1.21 2024-02-28 14:54:53 +01:00
strutil
teststorage TSDB: Fix some edge cases when OOO is enabled (#14710) 2024-10-23 17:34:28 +02:00
testutil Signed-off-by: crystalstall <crystalruby@qq.com> 2025-01-11 00:41:51 +08:00
treecache chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
zeropool chore: Fix typos (#14868) 2024-09-10 22:32:03 +02:00