mirror of
https://github.com/NetworkCats/rustyip.git
synced 2026-11-13 08:15:53 +00:00
Cache the serialized /json fields per MMDB record. Every field except `ip` depends only on the record, and many IPs share one record, so the response is now the cached fields with the address prepended. The cache is keyed by data-section offset, capped at 16 MiB, and owned by the loaded database so a hot-swapped DB never serves stale entries. A hit costs ~0.27us instead of ~2.5us for decode + serialize; a miss is no slower than before thanks to a pre-sized serialization buffer. Trim per-request framework overhead shared by all endpoints: - Dispatch by Host with a plain HostRouter service instead of an outer Router wrapping a service_fn, skipping a second route match and box. - Apply security headers via tower's MapResponseLayer instead of middleware::from_fn, and reserve header capacity up front. - Add a RequestedIp extractor that reads headers in place instead of cloning the whole HeaderMap. On a 1 CPU / 1 GB Alpine (musl) container, /json throughput rose from 76.5k to 123.5k rps for a single IP (+61%) and from 84.9k to 130.5k rps across 20k random IPs (+54%); p50 latency fell from 0.85ms to 0.52ms. Responses are byte-identical to before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>