Proposal: Skip existence check for file cache if user specifies ignoremissingimports #10206
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.
Context
Parsing of large amounts of msbuild projects (thousands) can hit some performance issues while utilizing the evaluation APIs. These performance issues can be overcome with some changes, however, further improvements can be made in the existence path. If a consumer is utilizing the evaluation APIs and is already specifying IgnoreMissingImports then existence really shouldn't be necessary and instead falling back to I/O try/catch logic that already exists should be sufficient. These existence checks force a round trip to the OS every time resulting in unnecessary pinvoke paths which can play a role in performance degradation. Again this is for large amounts of projects and is really for diabolical cases.
Changes Made
If a consumer is specifying IgnoreMissingImports we should ignore existence checks to avoid the unnecessary pinvoke roundtrip to the filesystem. The user needs to opt into this behavior by specifying the MSBUILDSKIPEXISTENCECHECKFORCACHE env var. So this feature is behind two gates: need this env var + need to IgnoreMissingImports.
Testing
Anecdotally seeing 50% perf improvement with this change when run against larger number of projects.
Notes