You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DownloadableCodeProjects/standalone-lab-projects/implement-performance-profiling/ContosoOnlineStore/ContosoOnlineStore.csproj
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,12 @@
5
5
<TargetFramework>net9.0</TargetFramework>
6
6
<ImplicitUsings>enable</ImplicitUsings>
7
7
<Nullable>enable</Nullable>
8
+
9
+
<!-- Enable optimizations even for Debug so that running the app with the
10
+
'benchmark' argument via 'dotnet run' produces valid BenchmarkDotNet results.
11
+
Without this, a Debug build shows a warning that the assembly is non-optimized. -->
Copy file name to clipboardExpand all lines: DownloadableCodeProjects/standalone-lab-projects/implement-performance-profiling/ContosoOnlineStore/PERFORMANCE_GUIDE.md
+99-4Lines changed: 99 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ This document outlines the intentional performance bottlenecks in the Contoso On
9
9
### 🔴 Critical Performance Issues
10
10
11
11
#### 1. Product Catalog Linear Search
12
+
12
13
**File**: `ProductCatalog.cs`
13
14
**Method**: `GetProductById()`
14
15
**Issue**: Uses linear search (FirstOrDefault) instead of dictionary lookup
@@ -23,65 +24,79 @@ return _productIndex.TryGetValue(productId, out var product) ? product : null;
**Expected Improvement**: 80%+ improvement in repeated operations
122
142
123
143
**Steps**:
144
+
124
145
1. Implement product search result caching
125
146
2. Add price calculation caching
126
147
3. Create smart cache invalidation
@@ -133,19 +154,65 @@ return _productIndex.TryGetValue(productId, out var product) ? product : null;
133
154
### Using Built-in Performance Tracking
134
155
135
156
The application includes performance counters that display:
157
+
136
158
- Order processing times
137
159
- Individual operation durations
138
160
- Memory allocation patterns
139
161
- Cache hit/miss ratios
140
162
141
163
### Running Benchmarks
142
164
143
-
Use BenchmarkDotNet for detailed analysis:
165
+
To use BenchmarkDotNet for detailed analysis, run the following command:
166
+
167
+
```bash
168
+
dotnet run -c Release -- benchmark
169
+
```
170
+
171
+
This command will run the application in Release mode and execute the benchmarks defined in your project.
172
+
173
+
If you omit the `-c Release` option, the compiler defaults to Debug mode. Since the default value for `Optimize` in a Debug build is `false`, BenchmarkDotNet will detect a non‑optimized assembly. The result is a warning or error “Assembly ... is non-optimized... build it in RELEASE.”
174
+
175
+
You can update the .csproj file to enable optimizations even for Debug mode so that running the app with the 'benchmark' argument via 'dotnet run' should produce valid BenchmarkDotNet results.
176
+
177
+
Add the following line inside the main `<PropertyGroup>` in the .csproj file.
178
+
179
+
```xml
180
+
<Optimize>true</Optimize>
181
+
```
182
+
183
+
Without this, a Debug build shows the warning/error that the assembly is non-optimized.
184
+
185
+
It's best to explicitly use Release (recommended for keeping Debug truly debuggable):
186
+
187
+
```bash
188
+
dotnet run -c Release -- benchmark
189
+
```
190
+
191
+
Warning: Always optimizing Debug can make stepping through code less intuitive. If you
192
+
prefer traditional debugging, revert the global <Optimize>true> and instead:
Copy file name to clipboardExpand all lines: DownloadableCodeProjects/standalone-lab-projects/implement-performance-profiling/ContosoOnlineStore/Tests/ContosoOnlineStoreTests.cs
0 commit comments