Skip to content

ltm: LTM_BENCH_TRACE should be cfg(any(test, feature = "ltm_bench")) instead of runtime env check #464

Closed

Description

@bpowers

Problem

src/simlin-engine/src/ltm_augment.rs::generate_loop_score_variables checks a runtime env var (LTM_BENCH_TRACE) on every compile, and the read_rss_mib() helper + should_trace() + all tracing eprintln!s are compiled into production builds even though the feature is strictly a benchmarking/diagnostic aid.

// src/simlin-engine/src/ltm_augment.rs:148
let trace_on = std::env::var(\"LTM_BENCH_TRACE\").is_ok();

A std::env::var lookup on every call to generate_loop_score_variables is a small tax (compared to the work the function already does) but the bigger issues are:

  1. Production WASM builds carry code that reads /proc/self/status (wrapped in #[cfg(target_os = \"linux\")] so it no-ops on non-Linux, but the stub path still ships).
  2. The dead-code bloat is non-trivial: read_rss_mib, should_trace, the eprintln! branches, and the byte-counter arithmetic all live in the release binary.
  3. Environment-variable feature gates invite accidental activation in deployed environments; a cargo feature makes the boundary explicit.

Proposed fix

Gate the tracing machinery behind #[cfg(any(test, feature = \"ltm_bench\"))] (or just a dedicated ltm_bench feature) and inline a no-op shim for the default build. The trace_on check, the byte counter, and the entire read_rss_mib/should_trace pair would then compile out entirely in the common case. Callers that benchmark LTM compilation can enable the feature explicitly when running the benches in benches/compiler.rs.

Severity

Low. The runtime cost is negligible and the correctness impact is zero. This is a code-organization / build-hygiene issue.

Discovery context

Noted during adversarial review of PR #461 (branch ltm-perf-enable-always).

Files

  • src/simlin-engine/src/ltm_augment.rs:143-188 (tracing machinery in generate_loop_score_variables)
  • src/simlin-engine/src/ltm_augment.rs:210-220+ (read_rss_mib, should_trace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions