| Crates.io | auto-allocator |
| lib.rs | auto-allocator |
| version | 0.1.0 |
| created_at | 2025-06-30 11:33:25.833634+00 |
| updated_at | 2025-06-30 11:33:25.833634+00 |
| description | Zero-configuration automatic memory allocator selection based on runtime hardware analysis and performance research |
| homepage | |
| repository | https://github.com/yeauty/auto-allocator |
| max_upload_size | |
| id | 1731729 |
| size | 184,996 |
π― One line of code. Platform-intelligent optimization. Zero configuration.
The smartest memory allocator for Rust that automatically selects the optimal allocator for your platform - delivering performance improvements where possible, and platform compliance where required.
π― Smart Optimization for Every Platform
β‘ Effortless Integration
use auto_allocator; and you're optimizedπ§ Platform Intelligence
[dependencies]
auto-allocator = "*"
use auto_allocator; // π Done! Memory allocation is now optimized
fn main() {
// Your existing code automatically benefits from optimal allocation
let data = vec![1, 2, 3, 4, 5];
let text = "Hello".repeat(1000);
// No changes needed - just faster memory operations!
println!("π High-performance allocation active!");
}
use auto_allocator;
fn main() {
let info = auto_allocator::get_allocator_info();
println!("β
Using: {:?}", info.allocator_type);
println!("π‘ {}", info.reason);
}
β¨ That's literally all you need! Auto-Allocator handles everything else automatically.
Auto-Allocator uses intelligent two-phase optimization:
π COMPILE TIME π RUNTIME β
RESULT
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Platform β β CPU Core Count β β β
β Detection ββββββββββββββββΆβ Analysis ββββββββββββΆβ Optimal β
β β β β β Allocator β
β Compiler β β Memory β β Selection β
β Analysis ββββββββββββββββΆβ Detection ββββββββββββΆβ β
β β β β β β
β Feature β β Hardware β β β
β Availability ββββββββββββββββΆβ Optimization ββββββββββββΆβ β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
π― 90% of decisions made at compile-time for zero runtime overhead
β‘ Only high-performance platforms need runtime CPU detection
| Platform | Selected Allocator | Expected Benefit | Technical Reason |
|---|---|---|---|
| π₯οΈ Windows/macOS/Linux (Multi-core) | mimalloc | 1.6x faster allocation | Microsoft Research-proven performance |
| π± Android | Scudo | Platform security compliance | Google's official security policy |
| π± iOS | libmalloc | Deep system integration | Apple's optimization recommendation |
| π BSD/Solaris | Native allocator | Already optimal | Platform-tuned performance |
| π€ Embedded | embedded-alloc | Resource efficiency | Designed for constraints |
| π Debug builds | System | Fast compilation | Development speed priority |
| π WASM | System | Browser compatibility | Web standard compliance |
When mimalloc is selected (Windows/macOS/Linux multi-core):
Test it yourself:
cargo bench # Benchmark your specific workload
Key insight: Auto-Allocator delivers performance improvements where they matter, while respecting platform policies elsewhere.
Security features are only available on platforms that use mimalloc-secure:
# Only effective on Windows/macOS/Linux with mimalloc support
[dependencies]
auto-allocator = { version = "*", features = ["secure"] }
| Platform | Secure Mode Effect | Security Features |
|---|---|---|
| π₯οΈ Windows/macOS/Linux | mimalloc-secure activated | Guard pages, encrypted free lists, randomization |
| π± Android | No change (uses Scudo) | Android's built-in security (UAF protection) |
| π± iOS | No change (uses libmalloc) | iOS system-level protections |
| π BSD/Solaris | No change (native allocators) | Platform built-in security hardening |
| π WASM | No change (browser sandbox) | Browser security model isolation |
| π€ Embedded | No change (resource constraints) | Standard embedded safety measures |
| Configuration | Performance | Security Level | Available On |
|---|---|---|---|
| Default | 100% speed | Rust safety + platform defaults | All platforms |
| Secure | 90% speed | Enhanced heap protection | Windows/macOS/Linux only |
π‘ Key insight: Many platforms already have excellent built-in security - Auto-Allocator respects and leverages these instead of overriding them.
use auto_allocator;
fn main() {
// π Inspect current allocator selection
let info = auto_allocator::get_allocator_info();
println!("π Active: {:?}", info.allocator_type);
println!("π‘ Why: {}", info.reason);
// π System specifications
println!("π₯οΈ Hardware: {} cores, {} RAM",
info.system_info.cpu_cores,
auto_allocator::format_memory_size(info.system_info.total_memory_bytes));
// β
Validate optimal configuration
let (is_optimal, suggestion) = auto_allocator::check_allocator_optimization();
if !is_optimal {
println!("β οΈ Optimization tip: {}", suggestion.unwrap());
}
// π― Get platform-specific recommendations
let (recommended, reason) = auto_allocator::get_recommended_allocator();
println!("π― Recommended: {:?} - {}", recommended, reason);
}
π― Peer-Reviewed Research:
Microsoft Research Study: 1.6x faster than jemalloc in production
Free-list sharding: Eliminates lock contention in multi-threaded applications
Cache-conscious design: Better memory locality = faster access patterns
Battle-tested: Powers Microsoft Azure, Office 365, and Windows services
Explore real-world usage in the examples/ directory:
| Example | Use Case | What You'll Learn |
|---|---|---|
| π simple_demo | Basic integration | Zero-config setup + system introspection |
| β optimization_check | CI/CD validation | Automated performance verification |
| π web_server | Production server | High-throughput web application |
| π€ embedded_system | IoT/Embedded | Resource-constrained optimization + Real no_std compilation |
Flexible licensing for maximum compatibility:
Choose the license that best fits your project!