Skip to content

Comments

perf(config): cache sys getenv#3670

Draft
morrisonlevi wants to merge 2 commits intomasterfrom
levi/cache-getenv
Draft

perf(config): cache sys getenv#3670
morrisonlevi wants to merge 2 commits intomasterfrom
levi/cache-getenv

Conversation

@morrisonlevi
Copy link
Collaborator

Description

In request initialization aka rinit/activate, calling the system getenv when a SAPI env var isn't found is slow enough it shows up in profiles:

image (1)

Note that glibc's getenv does a linear scan on the environ and does strncmp on the members, so we can definitely do better.

This is also arguably more correct: system environment variables map to a system INI setting, which shouldn't change at runtime.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@morrisonlevi morrisonlevi changed the title perf(config): caches sys getenv on minit perf(config): cache sys getenv on minit Feb 24, 2026
@datadog-official
Copy link

datadog-official bot commented Feb 24, 2026

⚠️ Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

🧪 1028 Tests failed

testSearchPhpBinaries from integration.DDTrace\Tests\Integration\PHPInstallerTest (Datadog) (Fix with Cursor)
DDTrace\Tests\Integration\PHPInstallerTest::testSearchPhpBinaries
Test code or tested code printed unexpected output: Searching for available php binaries, this operation might take a while.
testSimplePushAndProcess from laravel-58-test.DDTrace\Tests\Integrations\Laravel\V5_8\QueueTest (Datadog) (Fix with Cursor)
DDTrace\Tests\Integrations\Laravel\V5_8\QueueTest::testSimplePushAndProcess
Test code or tested code printed unexpected output: spanLinksTraceId: 699ee8e500000000c3b90521ff071a26
tid: 699ee8e500000000
hexProcessTraceId: c3b90521ff071a26
hexProcessSpanId: b88f6e41af859e1c
processTraceId: 14103309351658134054
processSpanId: 13298969453045063196

phpvfscomposer://tests/vendor/phpunit/phpunit/phpunit:106
testSimplePushAndProcess from laravel-8x-test.DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest (Datadog) (Fix with Cursor)
DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest::testSimplePushAndProcess
Test code or tested code printed unexpected output: spanLinksTraceId: 699ee7680000000089cb7bd0e9c8e652
tid: 699ee76800000000
hexProcessTraceId: 89cb7bd0e9c8e652
hexProcessSpanId: 03c9e6fa682c9559
processTraceId: 9929165940674061906
processSpanId: 273003215596590425
View all

ℹ️ Info

❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e26db1d | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.08%. Comparing base (25893da) to head (5a292ea).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3670   +/-   ##
=======================================
  Coverage   62.08%   62.08%           
=======================================
  Files         141      141           
  Lines       13352    13352           
  Branches     1746     1746           
=======================================
  Hits         8290     8290           
  Misses       4269     4269           
  Partials      793      793           

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25893da...5a292ea. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter
Copy link

pr-commenter bot commented Feb 24, 2026

Benchmarks [ tracer ]

Benchmark execution time: 2026-02-25 13:22:47

Comparing candidate commit e26db1d in PR branch levi/cache-getenv with baseline commit 07b618a in branch master.

Found 2 performance improvements and 6 performance regressions! Performance is the same for 186 metrics, 0 unstable metrics.

scenario:ComposerTelemetryBench/benchTelemetryParsing

  • 🟥 execution_time [+0.862µs; +1.738µs] or [+7.559%; +15.248%]

scenario:HookBench/benchHookOverheadTraceMethod-opcache

  • 🟥 execution_time [+3.551µs; +13.430µs] or [+2.047%; +7.743%]

scenario:MessagePackSerializationBench/benchMessagePackSerialization

  • 🟩 execution_time [-10.760µs; -8.940µs] or [-9.767%; -8.115%]

scenario:MessagePackSerializationBench/benchMessagePackSerialization-opcache

  • 🟩 execution_time [-9.814µs; -8.906µs] or [-8.814%; -7.999%]

scenario:SamplingRuleMatchingBench/benchRegexMatching1

  • 🟥 execution_time [+99.665ns; +155.935ns] or [+8.657%; +13.544%]

scenario:SamplingRuleMatchingBench/benchRegexMatching2

  • 🟥 execution_time [+113.060ns; +172.940ns] or [+9.848%; +15.064%]

scenario:SamplingRuleMatchingBench/benchRegexMatching3

  • 🟥 execution_time [+111.600ns; +184.000ns] or [+9.596%; +15.821%]

scenario:SamplingRuleMatchingBench/benchRegexMatching4

  • 🟥 execution_time [+113.780ns; +153.620ns] or [+9.918%; +13.391%]

@morrisonlevi morrisonlevi changed the title perf(config): cache sys getenv on minit perf(config): cache sys getenv Feb 24, 2026
In rinit, calling system getenv when a SAPI env var isn't found is
slow enough it shows up in profiles. glibc's getenv does a linear
scan on the environ and does strncmp on the members, so we can
definitely do better.

This is also arguably more correct: system environment variables map
to a system INI setting, which shouldn't change at runtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants