mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-09 07:39:19 -05:00
CopyObject takes the reader and decodes it with jsontext, accepting repeated names and invalid UTF-8 as encoding/json did. Keys are written with the bytes they were read with instead of being re-encoded. Member gets Skip, which reads past a value without keeping it, and npm's RewriteStream skips dropped versions and duplicates with it. conda-forge noarch repodata.json (195 MB): filtering 0.89 to 0.62 s and 379 to 77 MB allocated, the timestamp index 0.84 to 0.61 s. The next packument (32 MB): RewriteStream 69 to 34 ms and 38 to 3.5 MB.
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"log/slog"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/git-pkgs/cooldown"
|
|
)
|
|
|
|
// repodataBenchBody reads the repodata.json named by CONDA_REPODATA_BENCH,
|
|
// such as conda-forge's noarch one, and skips the benchmark without it.
|
|
func repodataBenchBody(b *testing.B) []byte {
|
|
b.Helper()
|
|
path := os.Getenv("CONDA_REPODATA_BENCH")
|
|
if path == "" {
|
|
b.Skip("CONDA_REPODATA_BENCH names no repodata.json")
|
|
}
|
|
body, err := os.ReadFile(path)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
return body
|
|
}
|
|
|
|
func BenchmarkCondaFilterRepodata(b *testing.B) {
|
|
body := repodataBenchBody(b)
|
|
policy, err := cooldown.NewPolicy(&cooldown.Config{Default: "3d"}, nil)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
proxy := testProxy()
|
|
proxy.Logger = slog.New(slog.DiscardHandler)
|
|
proxy.Cooldown = policy
|
|
h := NewCondaHandler(proxy, "http://proxy.example")
|
|
now := time.Now()
|
|
b.SetBytes(int64(len(body)))
|
|
b.ReportAllocs()
|
|
for b.Loop() {
|
|
if err := h.filterRepodataWith(bytes.NewReader(body), io.Discard, h.newRepodataFilter(now)); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkCondaReadRepodataIndex(b *testing.B) {
|
|
body := repodataBenchBody(b)
|
|
b.SetBytes(int64(len(body)))
|
|
b.ReportAllocs()
|
|
for b.Loop() {
|
|
index, err := readRepodataIndex(bytes.NewReader(body))
|
|
if err != nil || len(index) == 0 {
|
|
b.Fatalf("index of %d files, %v", len(index), err)
|
|
}
|
|
}
|
|
}
|