Memray memory profiling infrastructure added and hot-path allocations eliminated
46 files · 1,650+ · 119-

Memray memory profiling infrastructure

24 files changed
  • memray_logging_stress.py Stress test for logging hot path (73 lines)
  • memray_sampling_stress.py Stress test for sampling hot path (52 lines)
  • memray_pii_stress.py Stress test for PII sanitization hot path (66 lines)
  • memray_backpressure_stress.py Stress test for backpressure queue hot path (48 lines)
  • memray_tracing_stress.py Stress test for tracing decorator hot path (45 lines)
  • memray_metrics_stress.py Stress test for metrics recording hot path (41 lines)
  • memray_bounded_growth_stress.py Bounded-growth stress test: cardinality _seen pruning, SLO count, meter cache bounds (167 lines)
  • run_memray_stress.py Runner script orchestrating all memray stress scenarios (58 lines)
  • tracemalloc_audit.py Python-level allocation audit using tracemalloc (115 lines)
  • memray_analysis.py Flamegraph generation and stats reporting from .bin profiles (142 lines)
  • __init__.py Memray test package init
  • conftest.py pytest fixtures: baseline loading, tolerance enforcement, artifact paths (71 lines)
  • baselines.json Per-test allocation baselines tracked for regression comparison
  • test_logging_stress.py pytest memray test: logging hot path (51 lines)
  • test_sampling_stress.py pytest memray test: sampling hot path (51 lines)
  • test_pii_stress.py pytest memray test: PII sanitization hot path (51 lines)
  • test_backpressure_stress.py pytest memray test: backpressure queue hot path (51 lines)
  • test_tracing_stress.py pytest memray test: tracing decorator hot path (51 lines)
  • test_metrics_stress.py pytest memray test: metrics recording hot path (51 lines)
  • test_bounded_growth_stress.py pytest memray test: bounded-growth cardinality and cache checks (34 lines)
  • ci.yml Added memory-regression CI job (nightly + manual dispatch, artifact upload)
  • memory-audit.ts TypeScript memory/perf audit using process.memoryUsage and perf_hooks (119 lines)
  • package.json Added perf_hooks dependency for TypeScript memory audit
  • Makefile Makefile with memray, perf-smoke, lint, and test targets (38 lines)
  • Added 6 memray stress tests covering the key hot paths: logging, sampling, PII, backpressure, tracing decorator, and metrics recording qualify internal
    12 files
    • memray_logging_stress.py
    • memray_sampling_stress.py
    • memray_pii_stress.py
    • memray_backpressure_stress.py
    • memray_tracing_stress.py
    • memray_metrics_stress.py
    • test_logging_stress.py
    • test_sampling_stress.py
    • test_pii_stress.py
    • test_backpressure_stress.py
    • test_tracing_stress.py
    • test_metrics_stress.py
  • Added bounded-growth stress tests for cardinality _seen set pruning, SLO instrument count, and meter cache bounds qualify internal
    2 files
    • memray_bounded_growth_stress.py
    • test_bounded_growth_stress.py
  • pytest integration with 15% regression tolerance threshold; baselines tracked per-test in baselines.json qualify internal
    2 files
    • conftest.py
    • baselines.json
  • Added tools/tracemalloc_audit.py script for Python-level allocation tracing instantiate internal
    1 file
    • tracemalloc_audit.py
  • Added scripts/memray/memray_analysis.py for flamegraph generation from .bin profiles instantiate internal
    1 file
    • memray_analysis.py
  • CI memory-regression job: runs nightly and on manual dispatch, uploads memray artifacts baseline internal
    1 file
    • ci.yml

Hot-path allocations eliminated

13 files changed
  • backpressure.py Added slots=True to QueuePolicy and QueueTicket frozen dataclasses
  • cardinality.py Added slots=True to CardinalityLimit frozen dataclass
  • health.py Added slots=True to HealthSnapshot frozen dataclass
  • pretty.py Pre-computed frozenset of renderer field names in PrettyRenderer.__init__
  • processors.py Updated processors to use new direct trace/span ID accessors
  • fallback.py Updated fallback metrics to use direct span context accessors
  • pii.py Added module-level _REDACTED constant; added slots=True to PIIRule
  • propagation.py Added slots=True to PropagationContext frozen dataclass
  • resilience.py Added slots=True to ExporterPolicy frozen dataclass
  • runtime.py Replaced asdict() with getattr() in config comparison; fixed TOCTOU race in guard_attributes()
  • sampling.py Added slots=True to SamplingPolicy frozen dataclass
  • context.py Added direct get_trace_id() / get_span_id() accessors reading from span context
  • decorators.py Updated tracing decorators to use direct span context accessors
  • Added __slots__ = True to 8 frozen dataclasses: PIIRule, SamplingPolicy, ExporterPolicy, QueuePolicy, QueueTicket, CardinalityLimit, HealthSnapshot, PropagationContext — eliminates per-instance __dict__ allocation streamline internal
    7 files
    • pii.py
    • sampling.py
    • resilience.py
    • backpressure.py
    • cardinality.py
    • health.py
    • propagation.py
  • Added direct get_trace_id() / get_span_id() accessors in tracing/context.py that read directly from the span context instead of constructing and discarding a {"trace_id": ..., "span_id": ...} dict on every call streamline internal
    4 files
    • context.py
    • processors.py
    • decorators.py
    • fallback.py
  • Pre-computed frozenset of renderer field names in PrettyRenderer.__init__ instead of constructing it each call streamline internal
    1 file
    • pretty.py
  • Replaced asdict() with getattr() in runtime config comparison to avoid allocating a temporary dict for each comparison streamline internal
    1 file
    • runtime.py
  • Added module-level _REDACTED = "[REDACTED]" constant in pii.py — eliminates per-redaction string allocation streamline internal
    1 file
    • pii.py
  • Fixed TOCTOU race in guard_attributes(): attribute presence check and set are now atomic under the lock remediate internal
    1 file
    • runtime.py

Zero allocations per call achieved

5 files changed
  • run_performance_smoke.py Expanded with 4 new timing benchmarks: @trace decorator, Counter.add, Histogram.record, get_health_snapshot
  • test_run_performance_smoke.py Updated performance smoke tests for expanded benchmark set
  • test_processors_mutations.py Updated mutation tests for processors after accessor refactor
  • test_fallback_mutations.py Updated mutation tests for fallback metrics after accessor refactor
  • test_metrics_core.py Updated metrics core tests for new accessor patterns
  • Logging and tracing hot paths: zero allocations at both C-level (memray) and Python-level (tracemalloc) qualify behavioral
    3 files
    • test_logging_stress.py
    • test_tracing_stress.py
    • tracemalloc_audit.py
  • Memray baselines established for all 6 stress test paths qualify internal
    1 file
    • baselines.json