```python:inference/core/telemetry.py
from typing import Any, Dict, Optional

_metrics: Optional[Dict[str, Any]] = None

_cached_metrics_methods: Optional[tuple] = None


def record_inference(model_id: str, duration: float) -> None:
    """Record an inference execution."""
    if _metrics is None:
        return
    
    _cache = _cached_metrics_methods
    if _cache is None or _cache[0] is not _metrics:
        count_metric = _metrics["model_infer_count"]
        duration_metric = _metrics["model_infer_duration"]
        _cache = (_metrics, count_metric.add, duration_metric.record)
        globals()["_cached_metrics_methods"] = _cache
    
    _cache[1](1, {"model.id": model_id})
    _cache[2](duration, {"model.id": model_id})
```