Skip to content

RuntimeEnvironmentHelper: remove Lazy for basic platform checks#7485

Merged
kartheekp-ms merged 1 commit into
devfrom
dev-kapenaga-RuntimeEnvHelper-RemoveLazy
Jun 18, 2026
Merged

RuntimeEnvironmentHelper: remove Lazy for basic platform checks#7485
kartheekp-ms merged 1 commit into
devfrom
dev-kapenaga-RuntimeEnvHelper-RemoveLazy

Conversation

@kartheekp-ms

@kartheekp-ms kartheekp-ms commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#14951

Description

Thanks to @fowl2 for identifying this performance improvement. Given the PR is labeled as stale due to no activity and the performance improvements are good, we decided to make this change to the product.

Copied the below description from the community PR linked above.

IsOSPlatform() is fast, so remove all the overhead from using Lazy<>

Thanks to @nkolev92 for adding benchmarks showing performance improvements in #7416 (comment). I copied the benchmarks below for quick reference. Benchmarking showed measurable overhead in several platform-check scenarios, especially for Linux and Mono detection.

● Benchmark results (10,000 iterations per call, on Hyper-V):

┌───────────────┬─────────────────┬───────────────────┬─────────────┐
│ Method │ Baseline (Lazy) │ Proposed (direct) │ Δ │
├───────────────┼─────────────────┼───────────────────┼─────────────┤
│ IsWindows │ 8.59 µs │ 6.74 µs │ -22% ✅ │
├───────────────┼─────────────────┼───────────────────┼─────────────┤
│ IsMacOSX │ 6.61 µs │ 8.14 µs │ +23% ❌ │
├───────────────┼─────────────────┼───────────────────┼─────────────┤
│ IsLinux │ 6.56 µs │ 3.93 µs │ -40% ✅ │
├───────────────┼─────────────────┼───────────────────┼─────────────┤
│ IsMono │ 11.53 µs │ 3.91 µs │ -66% ✅ │

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • [ ] Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

IsOSPlatform() is fast, so remove all the overhead from using Lazy&lt;&gt;.

This change addresses the review comment to keep the BSD check on
framework too - using OSPlatform.Create("FREEBSD") for all target
frameworks instead of conditionally compiling it.

Also added an early IsWindows check in IsMono to avoid the Mono type
check on Windows, improving performance.

Co-authored-by: Copilot &lt;223556219+Copilot@users.noreply.github.com&gt;
@kartheekp-ms kartheekp-ms marked this pull request as ready for review June 17, 2026 16:38
@kartheekp-ms kartheekp-ms requested a review from a team as a code owner June 17, 2026 16:38
@kartheekp-ms kartheekp-ms requested review from jeffkl and zivkan June 17, 2026 16:38
@kartheekp-ms kartheekp-ms merged commit b67e16e into dev Jun 18, 2026
20 of 21 checks passed
@kartheekp-ms kartheekp-ms deleted the dev-kapenaga-RuntimeEnvHelper-RemoveLazy branch June 18, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RuntimeEnvironmentHelper: remove Lazy for basic platform checks

3 participants