mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-05 22:43:59 +00:00
bfb7e9875e
Adds an alternative HTTPDoer backed by valyala/fasthttp for high-throughput
bots. Cuts per-call allocs from 102 to 56 in the cross-library bench
(within 8 of telego, which uses fasthttp by default), and per-call bytes
from 11.1 KiB to 6.6 KiB.
bot := client.New(token,
client.WithHTTPClient(client.NewFastHTTPDoer()),
)
Implementation notes:
- Wraps *fasthttp.Client behind the existing HTTPDoer (Do *http.Request)
interface, so RetryDoer, custom transports, observability middleware,
and the 1428 generated tests all keep working as-is.
- Translates *http.Request -> fasthttp.Request once per call and
returns a *http.Response whose Body releases the pooled fasthttp
response on Close (net/http contract).
- Recognises the bufferReadCloser / readerReadCloser shapes produced
by buildRequest and passes their underlying bytes straight to
SetBodyRaw -- no io.ReadAll, no copy.
- Honours ctx.Deadline via DoDeadline, falls back to WithFastHTTPReadTimeout
when no deadline is set. fasthttp.ErrTimeout maps to
context.DeadlineExceeded for errors.Is compatibility.
Default stays net/http: fasthttp is HTTP/1.1 only, doesn't compose with
the http.RoundTripper middleware ecosystem, and most users don't have
the throughput to notice. Bots making thousands of API calls/sec should
opt in.
Multipart/file-upload path remains on net/http per the agreed scope --
the perf bottleneck was JSON-method round-trip, not file uploads.
Time numbers in the report deferred until a quiet-system bench run;
allocs/bytes numbers (which are deterministic per code path) are
already updated.
34 lines
1.2 KiB
Modula-2
34 lines
1.2 KiB
Modula-2
module github.com/lukaszraczylo/go-telegram/test/benchmarks
|
|
|
|
go 1.25.7
|
|
|
|
replace github.com/lukaszraczylo/go-telegram => ../../
|
|
|
|
require (
|
|
github.com/NicoNex/echotron/v3 v3.45.0
|
|
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
|
|
github.com/go-telegram/bot v1.20.0
|
|
github.com/lukaszraczylo/go-telegram v0.0.0-00010101000000-000000000000
|
|
github.com/mymmrac/telego v1.8.0
|
|
gopkg.in/telebot.v3 v3.3.8
|
|
)
|
|
|
|
require (
|
|
github.com/andybalholm/brotli v1.2.1 // indirect
|
|
github.com/bytedance/gopkg v0.1.3 // indirect
|
|
github.com/bytedance/sonic v1.15.0 // indirect
|
|
github.com/bytedance/sonic/loader v0.5.0 // indirect
|
|
github.com/cloudwego/base64x v0.1.6 // indirect
|
|
github.com/goccy/go-json v0.10.6 // indirect
|
|
github.com/grbit/go-json v0.11.0 // indirect
|
|
github.com/klauspost/compress v1.18.6 // indirect
|
|
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
|
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
|
github.com/valyala/fasthttp v1.71.0 // indirect
|
|
github.com/valyala/fastjson v1.6.10 // indirect
|
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
|
|
golang.org/x/sys v0.41.0 // indirect
|
|
golang.org/x/time v0.5.0 // indirect
|
|
)
|