provide-telemetry
2026-03-20
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.pyStress test for logging hot path (73 lines)memray_sampling_stress.pyStress test for sampling hot path (52 lines)memray_pii_stress.pyStress test for PII sanitization hot path (66 lines)memray_backpressure_stress.pyStress test for backpressure queue hot path (48 lines)memray_tracing_stress.pyStress test for tracing decorator hot path (45 lines)memray_metrics_stress.pyStress test for metrics recording hot path (41 lines)memray_bounded_growth_stress.pyBounded-growth stress test: cardinality _seen pruning, SLO count, meter cache bounds (167 lines)run_memray_stress.pyRunner script orchestrating all memray stress scenarios (58 lines)tracemalloc_audit.pyPython-level allocation audit using tracemalloc (115 lines)memray_analysis.pyFlamegraph generation and stats reporting from .bin profiles (142 lines)__init__.pyMemray test package initconftest.pypytest fixtures: baseline loading, tolerance enforcement, artifact paths (71 lines)baselines.jsonPer-test allocation baselines tracked for regression comparisontest_logging_stress.pypytest memray test: logging hot path (51 lines)test_sampling_stress.pypytest memray test: sampling hot path (51 lines)test_pii_stress.pypytest memray test: PII sanitization hot path (51 lines)test_backpressure_stress.pypytest memray test: backpressure queue hot path (51 lines)test_tracing_stress.pypytest memray test: tracing decorator hot path (51 lines)test_metrics_stress.pypytest memray test: metrics recording hot path (51 lines)test_bounded_growth_stress.pypytest memray test: bounded-growth cardinality and cache checks (34 lines)ci.ymlAdded memory-regression CI job (nightly + manual dispatch, artifact upload)memory-audit.tsTypeScript memory/perf audit using process.memoryUsage and perf_hooks (119 lines)package.jsonAdded perf_hooks dependency for TypeScript memory auditMakefileMakefile 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.pymemray_sampling_stress.pymemray_pii_stress.pymemray_backpressure_stress.pymemray_tracing_stress.pymemray_metrics_stress.pytest_logging_stress.pytest_sampling_stress.pytest_pii_stress.pytest_backpressure_stress.pytest_tracing_stress.pytest_metrics_stress.py
- Added bounded-growth stress tests for cardinality
_seenset pruning, SLO instrument count, and meter cache bounds qualify internal2 files
memray_bounded_growth_stress.pytest_bounded_growth_stress.py
- pytest integration with 15% regression tolerance threshold; baselines tracked per-test in baselines.json
qualify
internal
2 files
conftest.pybaselines.json
- Added
tools/tracemalloc_audit.pyscript for Python-level allocation tracing instantiate internal1 file
tracemalloc_audit.py
- Added
scripts/memray/memray_analysis.pyfor flamegraph generation from.binprofiles instantiate internal1 file
memray_analysis.py
- CI
memory-regressionjob: runs nightly and on manual dispatch, uploads memray artifacts baseline internal1 file
ci.yml
Hot-path allocations eliminated
13 files changed
backpressure.pyAdded slots=True to QueuePolicy and QueueTicket frozen dataclassescardinality.pyAdded slots=True to CardinalityLimit frozen dataclasshealth.pyAdded slots=True to HealthSnapshot frozen dataclasspretty.pyPre-computed frozenset of renderer field names in PrettyRenderer.__init__processors.pyUpdated processors to use new direct trace/span ID accessorsfallback.pyUpdated fallback metrics to use direct span context accessorspii.pyAdded module-level _REDACTED constant; added slots=True to PIIRulepropagation.pyAdded slots=True to PropagationContext frozen dataclassresilience.pyAdded slots=True to ExporterPolicy frozen dataclassruntime.pyReplaced asdict() with getattr() in config comparison; fixed TOCTOU race in guard_attributes()sampling.pyAdded slots=True to SamplingPolicy frozen dataclasscontext.pyAdded direct get_trace_id() / get_span_id() accessors reading from span contextdecorators.pyUpdated tracing decorators to use direct span context accessors
- Added
__slots__ = Trueto 8 frozen dataclasses:PIIRule,SamplingPolicy,ExporterPolicy,QueuePolicy,QueueTicket,CardinalityLimit,HealthSnapshot,PropagationContext— eliminates per-instance__dict__allocation streamline internal7 files
pii.pysampling.pyresilience.pybackpressure.pycardinality.pyhealth.pypropagation.py
- Added direct
get_trace_id()/get_span_id()accessors intracing/context.pythat read directly from the span context instead of constructing and discarding a{"trace_id": ..., "span_id": ...}dict on every call streamline internal4 files
context.pyprocessors.pydecorators.pyfallback.py
- Pre-computed
frozensetof renderer field names inPrettyRenderer.__init__instead of constructing it each call streamline internal1 file
pretty.py
- Replaced
asdict()withgetattr()in runtime config comparison to avoid allocating a temporary dict for each comparison streamline internal1 file
runtime.py
- Added module-level
_REDACTED = "[REDACTED]"constant inpii.py— eliminates per-redaction string allocation streamline internal1 file
pii.py
- Fixed TOCTOU race in
guard_attributes(): attribute presence check and set are now atomic under the lock remediate internal1 file
runtime.py
Zero allocations per call achieved
5 files changed
run_performance_smoke.pyExpanded with 4 new timing benchmarks: @trace decorator, Counter.add, Histogram.record, get_health_snapshottest_run_performance_smoke.pyUpdated performance smoke tests for expanded benchmark settest_processors_mutations.pyUpdated mutation tests for processors after accessor refactortest_fallback_mutations.pyUpdated mutation tests for fallback metrics after accessor refactortest_metrics_core.pyUpdated 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.pytest_tracing_stress.pytracemalloc_audit.py
- Memray baselines established for all 6 stress test paths
qualify
internal
1 file
baselines.json