Optimize Linux env var handling: avoid allocations when environment not accessed#43
Merged
adamsitnik merged 10 commits intomainfrom Dec 19, 2025
Merged
Conversation
- Check HasEnvironmentBeenAccessed before allocating env vars - Pass null to native layer when environment not accessed - Use extern environ in C code when envp is NULL - Update test to access Environment property when needed - Add new test for environment inheritance without access Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
- Clarify comment about .NET environment variable behavior - Extract env variable to improve C code readability Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…ot accessed Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Optimize Linux implementation for unaccessed environment vars
Optimize Linux env var handling: avoid allocations when environment not accessed
Dec 19, 2025
adamsitnik
reviewed
Dec 19, 2025
Owner
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
- Use 'is not null' syntax instead of '!= null' - Simplify FreeArray call by passing null-coalesced length - Add detailed comment explaining extern char **environ - Improve test to set unique env var and verify both cases Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Contributor
Author
adamsitnik
reviewed
Dec 19, 2025
Owner
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
- Remove _codeql_detected_source_root file - Simplify test to use Assert.Single with manual loop - Ensure test works on all OS by accessing Environment - Remove OS-specific conditional assertions - Use Windows commands for options2 as well Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Contributor
Author
adamsitnik
reviewed
Dec 19, 2025
Use Assert.Single directly with IEnumerable cast instead of manual loop Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Contributor
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
… and does not affect the real process environment
218a7bc to
d8a0a3b
Compare
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.
Optimization Plan: Linux Environment Variables
Benchmark Results
Before Optimization
After Optimization
Summary
Successfully optimized Linux environment variable handling by:
HasEnvironmentBeenAccessedbefore allocating native memorynullto native layer when environment not touchedextern char **environdirectly in C code whenenvpisNULLResults:
All PR Review Feedback Addressed:
is not nullsyntaxextern char **environOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.