perf: cache /tmp/dash0_env_vars instead of re-reading it on every call - #97
Open
RaphaelManke wants to merge 1 commit into
Open
perf: cache /tmp/dash0_env_vars instead of re-reading it on every call#97RaphaelManke wants to merge 1 commit into
RaphaelManke wants to merge 1 commit into
Conversation
try_read_env_from_file() did a blocking std::fs::read_to_string plus a fresh serde_json parse, with no caching, on every call. get_resources_attributes() calls it from 4 independent sites (metrics_creation.rs, span_creation.rs, span_mutations.rs, exporter.rs), so a single invocation emitting traces, logs, and metrics could trigger this file read and parse repeatedly. std::fs is synchronous; calling it from async code blocks the tokio worker thread for the syscall's duration, on every invocation, for the life of the warm container. The file is written once by opt/shared.sh at cold start and never changes again for the life of the execution environment, so it only needs to be read once per process. Cached behind a Mutex<Option<Arc<...>>> (matching the existing pattern in state/global.rs), with a #[cfg(test)] reset hook since this module's own tests intentionally rewrite the file mid-suite to exercise different scenarios. Measured in isolation (throwaway benchmark replicating the exact read+ parse call, since this crate has no [lib] target for a real criterion/ divan bench to attach to): 9.4us/call uncached vs 35ns/call cached, a 265x difference.
RaphaelManke
temporarily deployed
to
staging
September 10, 2026 14:09 — with
GitHub Actions
Inactive
RaphaelManke
temporarily deployed
to
staging
September 10, 2026 14:09 — with
GitHub Actions
Inactive
RaphaelManke
temporarily deployed
to
staging
September 10, 2026 14:09 — with
GitHub Actions
Inactive
RaphaelManke
temporarily deployed
to
staging
September 10, 2026 14:09 — with
GitHub Actions
Inactive
3 tasks
RaphaelManke
had a problem deploying
to
staging
September 10, 2026 14:15 — with
GitHub Actions
Failure
RaphaelManke
temporarily deployed
to
staging
September 10, 2026 14:15 — with
GitHub Actions
Inactive
RaphaelManke
temporarily deployed
to
staging
September 10, 2026 14:15 — with
GitHub Actions
Inactive
RaphaelManke
had a problem deploying
to
staging
September 10, 2026 14:33 — with
GitHub Actions
Failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
try_read_env_from_file()did a blockingstd::fs::read_to_string+ a freshserde_jsonparse on every call, with no caching.get_resources_attributes()calls it from 4 independent sites (metrics_creation.rs,span_creation.rs,span_mutations.rs,exporter.rs), so a single invocation emitting traces, logs, and metrics could trigger this read+parse repeatedly.std::fsis synchronous; calling it from async code blocks the tokio worker thread for the syscall's duration -- on every invocation, for the life of the warm container.opt/shared.shat cold start and never changes again for the life of the execution environment, so it only needs to be read once per process.Fix
Cached behind
Mutex<Option<Arc<Option<serde_json::Value>>>>, matching the existing shared-state pattern already used instate/global.rs. Added a#[cfg(test)]reset hook and called it at the top of the module's existing tests, since they intentionally rewrite the file mid-suite to exercise different fallback scenarios -- without the reset they'd silently see a previous test's cached content.Measured
This crate has no
[lib]target for a realcriterion/divanbench to attach to, so measured in isolation by replicating the exact read+parse call in a throwaway benchmark: 9.4us/call uncached vs. 35ns/call cached -- a 265x difference.Test plan
cargo build --releasecargo test --release(325/325 passing, including all 7otlp::resources::tests::*)