You are an Expert RUST DEVELOPER and PERFORMANCE OPTIMIZATION SPECIALIST. Your task is to PROVIDE GUIDANCE on how to optimize and simplify Rust code using the latest libraries (also known as "bibolettes") for maximum performance, with a focus on parallelism, caching, and other performance-enhancing techniques.

Here's your step-by-step guide:

1. REVIEW the existing codebase to identify areas that could benefit from optimization.
2. ENSURE that you are indeed using Rust Nightly 1.85, which will allow you to take advantage of the LATEST FEATURES and optimizations.
3. UPDATE any OUTDATED DEPENDENCIES to the most recent versions that are COMPATIBLE with Rust Nightly 1.85.
4. IDENTIFY opportunities for PARALLELISM in the code where tasks can be executed concurrently, leveraging libraries like Rayon for data-parallel operations.
5. IMPLEMENT CACHING mechanisms where appropriate to avoid redundant computations, possibly using crates like `cached` or designing custom solutions.
6. APPLY 'zero-cost abstractions' and other RUST-SPECIFIC OPTIMIZATIONS such as iterator chaining and borrowing efficiently to ensure minimal overhead.
7. PROFILE the application using tools like `perf` or `cargo-flamegraph` to pinpoint bottlenecks and further refine your optimizations.

You MUST follow these steps meticulously to ACHIEVE peak performance from your Rust applications.

Remember, I’m going to tip $300K for a BETTER SOLUTION!

Now Take a Deep Breath.

```rust

use papaya::HashMap;
use lingua::Language::{
    Arabic, Chinese, English, French, German, Italian, Japanese, Korean, Latvian, Lithuanian,
    Russian, Spanish,
};
use lingua::{LanguageDetector, LanguageDetectorBuilder};
use ntex::web::types::Query;
use ntex::web::{self, App, HttpResponse, HttpServer, Responder};
use once_cell::sync::Lazy;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::time::{Duration, Instant};
use sysinfo::System;

static TOTAL_REQUESTS: AtomicUsize = AtomicUsize::new(0);
static CACHE_HITS: AtomicUsize = AtomicUsize::new(0);
static TOTAL_CACHE_TIME: AtomicU64 = AtomicU64::new(0);
static TOTAL_DETECTION_TIME: AtomicU64 = AtomicU64::new(0);
static DETECTION_COUNT: AtomicUsize = AtomicUsize::new(0);

static SYSTEM: Lazy<std::sync::Mutex<System>> = Lazy::new(|| {
    let mut sys = System::new_all();
    sys.refresh_all();
    std::sync::Mutex::new(sys)
});

#[derive(Deserialize)]
struct DetectQuery {
    text: String,
}

#[derive(Clone)]
struct CacheEntry {
    lang_code: String,
    timestamp: Instant,
}

#[derive(Serialize)]
struct CpuInfo {
    model: String,
    usage: f32,
    frequency: u64,
    cores: usize,
}

#[derive(Serialize)]
struct Stats {
    cpu: CpuInfo,
    memory_used_mb: u64,
    total_memory_mb: u64,
    total_requests: usize,
    cache_hits: usize,
    cache_hit_ratio: f64,
    cache_entries: usize,
    uptime_secs: u64,
    avg_cache_time_micros: u64,
    avg_detection_time_micros: u64,
}

static CACHE: Lazy<HashMap<String, CacheEntry>> = Lazy::new(HashMap::new);
static CACHE_DURATION: Duration = Duration::from_secs(43200); // 12 hours
static DETECTOR: Lazy<LanguageDetector> = Lazy::new(|| {
    eprintln!("Initializing language detector");
    LanguageDetectorBuilder::from_languages(&[
        Arabic, Chinese, English, French, German, Italian, Japanese, Korean, Russian, Spanish,
        Lithuanian, Latvian,
    ])
    .with_preloaded_language_models()
    .build()
});

#[inline]
fn build_response(body: String) -> HttpResponse {
    HttpResponse::Ok()
        .header("Access-Control-Allow-Origin", "*")
        .header("Cache-Control", "max-age=3600")
        .header("Access-Control-Allow-Headers", "*")
        .body(body)
}

#[inline]
fn update_cache(text: &str, lang_code: String) {
    CACHE.pin().insert(
        text.to_string(),
        CacheEntry {
            lang_code,
            timestamp: Instant::now(),
        }
    );
}

#[inline]
fn clean_expired_entries() {
    let now = Instant::now();
    CACHE.pin().retain(|_, entry| now.duration_since(entry.timestamp) < CACHE_DURATION);
}

async fn detect_and_respond(text: &str) -> impl Responder {
    let start_time = Instant::now();
    TOTAL_REQUESTS.fetch_add(1, Ordering::SeqCst);

    clean_expired_entries();

    if let Some(entry) = CACHE.pin().get(text) {
        eprintln!("Cache hit for text: {}", text);
        CACHE_HITS.fetch_add(1, Ordering::SeqCst);
        let cache_time = start_time.elapsed().as_micros() as u64;
        TOTAL_CACHE_TIME.fetch_add(cache_time, Ordering::SeqCst);
        return build_response(entry.lang_code.clone());
    }

    eprintln!("Detecting language for text: {}", text);
    let detection_start = Instant::now();
    
    let lang_code = DETECTOR
        .compute_language_confidence_values(text)
        .par_iter()
        .max_by(|a, b| a.1.partial_cmp(&b.1).unwrap())
        .map(|(lang, _)| lang.iso_code_639_1().to_string())
        .unwrap_or_else(|| "auto".to_string());

    let detection_time = detection_start.elapsed().as_micros() as u64;
    TOTAL_DETECTION_TIME.fetch_add(detection_time, Ordering::SeqCst);
    DETECTION_COUNT.fetch_add(1, Ordering::SeqCst);

    update_cache(text, lang_code.clone());
    build_response(lang_code)
}

async fn detect_language_handler(body: String) -> impl Responder {
    eprintln!("Received POST request");
    detect_and_respond(&body).await
}

async fn detect_language_get(query: Query<DetectQuery>) -> impl Responder {
    eprintln!("Received GET request");
    detect_and_respond(&query.text).await
}

async fn stats_handler() -> impl Responder {
    let mut sys = SYSTEM.lock().unwrap();
    sys.refresh_all();

    let total_requests = TOTAL_REQUESTS.load(Ordering::SeqCst);
    let cache_hits = CACHE_HITS.load(Ordering::SeqCst);
    let cache_hit_ratio = if total_requests > 0 {
        (cache_hits as f64 / total_requests as f64) * 100.0
    } else {
        0.0
    };

    let cpu_info = CpuInfo {
        model: sys.cpus()[0].brand().to_string(),
        usage: sys.global_cpu_usage(),
        frequency: sys.cpus()[0].frequency(),
        cores: sys.cpus().len(),
    };

    let avg_cache_time = if cache_hits > 0 {
        TOTAL_CACHE_TIME.load(Ordering::SeqCst) / cache_hits as u64
    } else {
        0
    };

    let detection_count = DETECTION_COUNT.load(Ordering::SeqCst);
    let avg_detection_time = if detection_count > 0 {
        TOTAL_DETECTION_TIME.load(Ordering::SeqCst) / detection_count as u64
    } else {
        0
    };

    let stats = Stats {
        cpu: cpu_info,
        memory_used_mb: sys.used_memory() / 1024 / 1024,
        total_memory_mb: sys.total_memory() / 1024 / 1024,
        total_requests,
        cache_hits,
        cache_hit_ratio,
        cache_entries: CACHE.len(),
        uptime_secs: System::uptime(),
        avg_cache_time_micros: avg_cache_time,
        avg_detection_time_micros: avg_detection_time,
    };

    HttpResponse::Ok()
        .content_type("application/json")
        .json(&stats)
}

#[ntex::main]
async fn main() -> std::io::Result<()> {
    env_logger::init();
    eprintln!("Starting language detection server");

    HttpServer::new(|| {
        App::new()
            .service(
                web::resource("/detect")
                    .route(web::post().to(detect_language_handler))
                    .route(web::get().to(detect_language_get)),
            )
            .service(web::resource("/stats").route(web::get().to(stats_handler)))
    })
    .bind("0.0.0.0:8080")?
    .run()
    .await
}

```