Traits: This caches values of various environment variables which act…#3385
Traits: This caches values of various environment variables which act…#3385cdmihai merged 1 commit intodotnet:masterfrom
Conversation
rainersigwald
left a comment
There was a problem hiding this comment.
Seems fine, but I'd ideally like an RPS run to double-check that it doesn't cause a noticeable perf problem.
|
I'm a little concerned with this one. RunningTests is cached so that's fast, but checking an environment variable to see if it should cache an environment variable look up on every call is not great. Also this could end up loading BuildEnvironmentHelper earlier which I'm not crazy about (it uses reflection and there are weird VS scenarios that we've seen in the past). This isn't a blocker but I'd rather not if we don't actually need it. How about on first access creating the Singleton we check |
|
@radical |
I'm not sure what you mean by that. But I noticed that we set this environment variable in TestEnvironment..ctor, so at least for all users of And yes, removing that didn't break any tests. |
Yup, I think the environment variable is obsolete. You can delete all read / write mentions to it. I remember that in the past, we relied on the env var as a way for tests to communicate to the Traits to refresh themselves. We needed the var because Traits is compiled into every assembly, so every assembly has it's own copy of the object, and we had no easy way of addressing all of them. But now we use reflection as a single source of truth, which makes me believe we don't need the env var at all. |
.. switches to control features like logging imports. For use with tests, this caching can be disabled but that is enabled only for DEBUG builds. Which means that any tests trying to toggle and test those environment variable dependent features will work only for debug builds. This is also controlled by the environment variable, `MSBUILDRELOADTRAITSONEACHACCESS`, which is no longer required. @cdmihai: I remember that in the past, we relied on the env var as a way for tests to communicate to the Traits to refresh themselves. We needed the var because Traits is compiled into every assembly, so every assembly has it's own copy of the object, and we had no easy way of addressing all of them. But now we use reflection as a single source of truth, which makes me believe we don't need the env var at all. (dotnet#3385 (comment))
96f5b78 to
3339c37
Compare
|
Updated to remove all uses of the env var. |
|
@dotnet-bot test OSX10.13 Build for CoreCLR please This is cleaner, I like it. And hopefully there aren't issues pulling BuildEnvironmentHelper here :). |
|
@dotnet-bot test Windows_NT Build for CoreCLR please |
… as (#42)
.. switches to control features like logging imports. For use with
tests, this caching can be disabled but that is enabled only for DEBUG
builds. Which means that any tests trying to toggle and test those
environment variable dependent features will work only for debug builds.
So, we remove that restriction. And because the condition first checks if we are
running tests and only then looks at
.. it shouldn't affect performance much (untested!).