Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## 0.27.2 - 2026-02-14
Comment thread
coderabbitai[bot] marked this conversation as resolved.

- Performance improvement: Faster lookups and record decoding in common paths,
including control-byte header parsing and integer decoding.
- Performance improvement: Faster string decoding for ASCII-only values by
using a dedicated ASCII fast path.
- Performance improvement: Reduced release-build overhead by compiling out
debug/trace logging calls.
- Fixed: Truncated or corrupt data in control-byte headers now returns a
decoding error instead of panicking.

## 0.27.1 - 2025-12-18

- Performance improvement: Skipped UTF-8 validation for map keys during
Expand Down
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "maxminddb"
version = "0.27.1"
version = "0.27.2"
authors = [ "Gregory J. Oschwald <oschwald@gmail.com>" ]
description = "Library for reading MaxMind DB format used by GeoIP2 and GeoLite2"
readme = "README.md"
Expand All @@ -27,7 +27,7 @@ name = "maxminddb"

[dependencies]
ipnetwork = "0.21.1"
log = "0.4"
log = { version = "0.4", features = ["release_max_level_info"] }
serde = { version = "1.0", features = ["derive"] }
memchr = "2.4"
memmap2 = { version = "0.9.0", optional = true }
Expand All @@ -37,10 +37,13 @@ thiserror = "2.0"
[dev-dependencies]
env_logger = "0.11"
criterion = "0.8"
fake = "4.0"
rayon = "1.5"
serde_json = "1.0"

[[bench]]
name = "lookup"
harness = false

[[bench]]
name = "serde_usage"
harness = false
21 changes: 21 additions & 0 deletions benches/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::net::{IpAddr, Ipv4Addr};

// Generate `count` IPv4 addresses from a deterministic LCG stream.
#[must_use]
pub fn generate_ipv4(count: u64) -> Vec<IpAddr> {
let mut ips = Vec::with_capacity(count as usize);
let mut state = 0x4D59_5DF4_D0F3_3173_u64;
for _ in 0..count {
state = state
.wrapping_mul(6_364_136_223_846_793_005)
.wrapping_add(1_442_695_040_888_963_407);
let ip = Ipv4Addr::new(
(state >> 24) as u8,
(state >> 32) as u8,
(state >> 40) as u8,
(state >> 48) as u8,
);
ips.push(IpAddr::V4(ip));
}
ips
}
20 changes: 3 additions & 17 deletions benches/lookup.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
#[macro_use]
extern crate criterion;
extern crate fake;
extern crate maxminddb;
extern crate rayon;

use criterion::Criterion;
use fake::faker::internet::raw::IPv4;
use fake::locales::EN;
use fake::Fake;
use maxminddb::geoip2;
use rayon::prelude::*;

use std::net::IpAddr;
use std::str::FromStr;

// Generate `count` IPv4 addresses
#[must_use]
pub fn generate_ipv4(count: u64) -> Vec<IpAddr> {
let mut ips = Vec::new();
for _i in 0..count {
let val: String = IPv4(EN).fake();
let ip: IpAddr = FromStr::from_str(&val).unwrap();
ips.push(ip);
}
ips
}
mod common;
use common::generate_ipv4;

// Single-threaded
pub fn bench_maxminddb<T>(ips: &[IpAddr], reader: &maxminddb::Reader<T>)
Expand Down Expand Up @@ -81,7 +67,7 @@ pub fn criterion_par_benchmark(c: &mut Criterion) {
criterion_group! {
name = benches;
config = Criterion::default()
.sample_size(10);
.sample_size(20);

targets = criterion_benchmark, criterion_par_benchmark
}
Expand Down
112 changes: 112 additions & 0 deletions benches/serde_usage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use criterion::{criterion_group, criterion_main, Criterion};
use maxminddb::geoip2;
use maxminddb::{LookupResult, PathElement, Reader};
use std::hint::black_box;

use std::net::IpAddr;

mod common;
use common::generate_ipv4;

const DB_FILE: &str = "GeoLite2-City.mmdb";

fn cache_lookups<'a, T>(ips: &[IpAddr], reader: &'a Reader<T>) -> Vec<LookupResult<'a, T>>
where
T: AsRef<[u8]>,
{
ips.iter()
.map(|ip| reader.lookup(*ip).unwrap())
.filter(|r| r.has_data())
.collect()
}

fn bench_lookup_only<T>(ips: &[IpAddr], reader: &Reader<T>)
where
T: AsRef<[u8]>,
{
for ip in ips {
let result = reader.lookup(*ip).unwrap();
black_box(result.has_data());
}
}

fn bench_decode_city_only<T>(results: &[LookupResult<'_, T>])
where
T: AsRef<[u8]>,
{
for result in results {
let city: Option<geoip2::City<'_>> = result.decode().unwrap();
black_box(city);
}
}

fn bench_decode_country_only<T>(results: &[LookupResult<'_, T>])
where
T: AsRef<[u8]>,
{
for result in results {
let country: Option<geoip2::Country<'_>> = result.decode().unwrap();
black_box(country);
}
}

fn bench_decode_path_country_iso<T>(results: &[LookupResult<'_, T>])
where
T: AsRef<[u8]>,
{
let path = [PathElement::Key("country"), PathElement::Key("iso_code")];
for result in results {
let value: Option<&str> = result.decode_path(&path).unwrap();
black_box(value);
}
}

fn bench_decode_path_city_name<T>(results: &[LookupResult<'_, T>])
where
T: AsRef<[u8]>,
{
let path = [
PathElement::Key("city"),
PathElement::Key("names"),
PathElement::Key("en"),
];
for result in results {
let value: Option<&str> = result.decode_path(&path).unwrap();
black_box(value);
}
}

pub fn serde_usage_benchmark(c: &mut Criterion) {
let ips = generate_ipv4(100);

#[cfg(not(feature = "mmap"))]
let reader = Reader::open_readfile(DB_FILE).unwrap();
#[cfg(feature = "mmap")]
// SAFETY: The benchmark database file will not be modified during the benchmark.
let reader = unsafe { Reader::open_mmap(DB_FILE) }.unwrap();

let cached_results = cache_lookups(&ips, &reader);

c.bench_function("serde_usage/lookup_only", |b| {
b.iter(|| bench_lookup_only(&ips, &reader))
});
c.bench_function("serde_usage/decode_city_only", |b| {
b.iter(|| bench_decode_city_only(&cached_results))
});
c.bench_function("serde_usage/decode_country_only", |b| {
b.iter(|| bench_decode_country_only(&cached_results))
});
c.bench_function("serde_usage/decode_path_country_iso", |b| {
b.iter(|| bench_decode_path_country_iso(&cached_results))
});
c.bench_function("serde_usage/decode_path_city_name", |b| {
b.iter(|| bench_decode_path_city_name(&cached_results))
});
}

criterion_group! {
name = benches;
config = Criterion::default().sample_size(20);
targets = serde_usage_benchmark
}
criterion_main!(benches);
Loading