MCPcopy Index your code
hub / github.com/YeautyYE/auto-allocator

github.com/YeautyYE/auto-allocator @v0.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.0 ↗ · + Follow
63 symbols 123 edges 9 files 22 documented · 35% updated 12mo agov0.1.0 · 2025-06-30★ 37
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🚀 Auto-Allocator

Crates.io Documentation License: MIT/Apache-2.0/MPL-2.0 Rust Version

🎯 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.

🌟 Why Developers Choose Auto-Allocator

🎯 Smart Optimization for Every Platform - Performance where it helps: 1.6x faster on multi-core Windows/macOS/Linux (Microsoft Research) - Compliance where it matters: Respects Android/iOS official policies
- Efficiency everywhere: Optimal allocation from servers to microcontrollers

⚡ Effortless Integration
- Truly zero-config - just use auto_allocator; and you're optimized - Universal compatibility - works on every Rust platform - Production ready - handles platform differences automatically

🧠 Platform Intelligence - Respects each platform's strengths - leverages native optimizations when better - Hardware-aware - adapts to CPU cores and memory constraints - Research-backed - every choice has technical justification

⚡ Quick Start

1. Add Dependency

[dependencies]
auto-allocator = "*"

2. Import and Use

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!");
}

3. Verify Optimization (Optional)

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.

🔬 How It Works

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-Specific Selection

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

🚀 Performance Results

When mimalloc is selected (Windows/macOS/Linux multi-core): - 1.6x faster allocation in multi-threaded scenarios (Microsoft Research) - Reduced lock contention through free-list sharding - Better cache locality and lower memory fragmentation

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

🔒 When Available (Platform-Dependent)

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-Specific Security

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

📊 Security Trade-offs

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.

🛠️ Advanced Usage

🔍 Check What's Being Used

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);
}

🔬 Technical Deep-Dive

🏆 Why mimalloc Dominates Performance

🎯 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

💡 Examples & Tutorials

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

📄 License

Flexible licensing for maximum compatibility:

Choose the license that best fits your project!

🎓 Research & References

📚 Core Research

🏢 Platform Documentation

Core symbols most depended-on inside this repo

print_str
called by 17
examples/embedded_system/src/main.rs
collect_system_info
called by 15
src/lib.rs
get_allocator_info
called by 12
src/lib.rs
smart_try_flush_log
called by 4
src/lib.rs
ensure_allocator_info_ready
called by 4
src/lib.rs
get_allocator_selection_result
called by 3
src/lib.rs
can_use_mimalloc_on_linux
called by 2
build.rs
print_compilation_error_and_exit
called by 2
build.rs

Shape

Function 52
Class 5
Method 5
Enum 1

Languages

Rust100%

Modules by API surface

src/lib.rs31 symbols
build.rs8 symbols
tests/platform_compatibility.rs7 symbols
examples/embedded_system/src/main.rs6 symbols
benches/allocator_benchmark.rs5 symbols
examples/web_server/main.rs3 symbols
examples/simple_demo/main.rs1 symbols
examples/optimization_check/main.rs1 symbols
examples/embedded_system/build.rs1 symbols

For agents

$ claude mcp add auto-allocator \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact