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: Instructions/Labs/LAB_AK_10_implement_performance_profiling.md
+42-40Lines changed: 42 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -208,13 +208,13 @@ Use the following steps to complete this task:
208
208
209
209
GitHub Copilot uses files that are open in the editor to establish context. Having only the target files open helps focus the analysis on the code you want to optimize.
210
210
211
-
1. Add the **ProductCatalog.cs**, **OrderProcessor.cs**, and **InventoryManager.cs** files to the Chat context.
211
+
1. Add the **InventoryManager.cs**, **OrderProcessor.cs**, and **ProductCatalog.cs** files to the Chat context.
212
212
213
-
Use a drag-and-drop operation to add **ProductCatalog.cs**, **OrderProcessor.cs**, and **InventoryManager.cs** from the SOLUTION EXPLORER to the Chat context.
213
+
Use a drag-and-drop operation to add **InventoryManager.cs**, **OrderProcessor.cs**, and **ProductCatalog.cs** from the SOLUTION EXPLORER to the Chat context.
214
214
215
215
Adding files to the chat context tells GitHub Copilot to include those files when analyzing your prompts, which improves the accuracy and relevance of its analysis.
216
216
217
-
1. Ask GitHub Copilot to identify performance bottlenecks in the ProductCatalog class.
217
+
1. Ask GitHub Copilot to identify performance bottlenecks in the ProductCatalog class and suggest optimizations.
218
218
219
219
For example, enter the following prompt in the Chat view:
220
220
@@ -224,12 +224,12 @@ Use the following steps to complete this task:
224
224
225
225
Review GitHub Copilot's analysis, which should identify issues such as:
226
226
227
-
- Linear search performance in GetProductById for certain conditions
228
-
- Inefficient cache key generation in SearchProducts
229
-
- Sequential processing with artificial delays
230
-
- Missing optimized data structures for category filtering
227
+
- Linear search performance in GetProductById for certain conditions.
228
+
- Inefficient cache key generation in SearchProducts.
229
+
- Missing optimized data structures for category filtering in GetProductsByCategory.
230
+
- Sequential processing with artificial delays in several of the methods.
231
231
232
-
1. Ask GitHub Copilot to analyze the OrderProcessor performance issues.
232
+
1. Ask GitHub Copilot to identify performance issues in the OrderProcessor class and suggest optimizations.
233
233
234
234
For example, submit the following prompt:
235
235
@@ -239,12 +239,12 @@ Use the following steps to complete this task:
239
239
240
240
GitHub Copilot should identify problems including:
241
241
242
-
- Individual product lookups in loops (N+1 query pattern)
243
-
- Redundant tax and shipping calculations
244
-
- Sequential processing of order items
245
-
- Blocking operations that could be made asynchronous
242
+
- Individual product lookups in loops (N+1 query pattern).
243
+
- Redundant tax and shipping calculations.
244
+
- Sequential processing of order items.
245
+
- Blocking operations that could be made asynchronous.
246
246
247
-
1. Analyze the InventoryManager for efficiency issues.
247
+
1. Ask GitHub Copilot to identify performance issues in the InventoryManager class and suggest optimizations.
248
248
249
249
For example, use this prompt to examine inventory operations:
250
250
@@ -254,12 +254,12 @@ Use the following steps to complete this task:
254
254
255
255
The analysis should reveal:
256
256
257
-
- Individual database query simulation in loops
258
-
- Inefficient logging implementation with blocking operations
259
-
- Missing batch operation support
260
-
- Unnecessary thread delays in stock level checks
257
+
- Individual database query simulation in loops.
258
+
- Inefficient logging implementation with blocking operations.
259
+
- Missing batch operation support.
260
+
- Unnecessary thread delays in stock level checks.
261
261
262
-
1. Ask about the EmailService performance characteristics.
262
+
1. Ask GitHub Copilot to identify performance issues in the EmailService class and suggest optimizations.
263
263
264
264
For example, submit this prompt to analyze the email service:
265
265
@@ -269,16 +269,18 @@ Use the following steps to complete this task:
269
269
270
270
GitHub Copilot should identify:
271
271
272
-
- Sequential email content generation with blocking operations
273
-
- Individual product lookups within email templates
274
-
- Synchronous validation operations
275
-
- Missing parallelization opportunities for multiple recipients
272
+
- Sequential email content generation with blocking operations.
273
+
- Individual product lookups within email templates.
274
+
- Synchronous validation operations.
275
+
- Missing parallelization opportunities for multiple recipients.
276
276
277
277
By using GitHub Copilot's analytical capabilities, you've identified the main performance bottlenecks in the ContosoOnlineStore application. The analysis provides a roadmap for optimization efforts, focusing on algorithmic improvements, caching strategies, and asynchronous processing patterns.
278
278
279
279
### Refactor performance-critical code using GitHub Copilot Chat (Agent mode)
280
280
281
-
GitHub Copilot Chat's Agent mode enables collaborative code refactoring where you can request specific code changes and improvements. In Agent mode, Copilot can generate optimized code implementations, suggest architectural improvements, and help implement performance enhancements.
281
+
GitHub Copilot's Agent mode provides an autonomous agent that assists with programming tasks. Developers assign high-level tasks and then start an agentic code editing session to accomplish the task. In agent mode, Copilot autonomously plans the work needed and determines the relevant files and context. The agent can make changes to your code, run tests, and even deploy your application.
282
+
283
+
In Agent mode, GitHub Copilot can generate optimized code implementations, suggest architectural improvements, and help implement performance enhancements.
282
284
283
285
In this task, you'll use GitHub Copilot Agent mode to systematically address the performance bottlenecks identified in the previous task.
284
286
@@ -288,51 +290,51 @@ Use the following steps to complete this task:
288
290
289
291
In the Chat view, change the mode from **Ask** to **Agent**. Agent mode provides more targeted code generation and modification capabilities.
290
292
291
-
1. Optimize the ProductCatalog GetProductById method.
293
+
1. Assign a task to the agent that optimizes the GetProductById method in the ProductCatalog class.
292
294
293
-
Open **ProductCatalog.cs** and select the `GetProductById` method. Use the following prompt in Chat:
295
+
Open **ProductCatalog.cs** and select the **GetProductById** method. Use the following prompt in Chat:
294
296
295
297
```text
296
298
Optimize this GetProductById method to improve performance. Consider using a dictionary lookup instead of linear search and implement proper caching mechanisms.
297
299
```
298
300
299
301
Review GitHub Copilot's suggested improvements and implement the changes. The optimized version should include:
300
302
301
-
- Dictionary-based product lookups for O(1) performance
302
-
- Proper cache initialization and management
303
-
- Reduced redundant operations
303
+
- Dictionary-based product lookups for O(1) performance.
304
+
- Proper cache initialization and management.
305
+
- Reduced redundant operations.
304
306
305
-
1. Enhance the SearchProducts method efficiency.
307
+
1. Assign a task to the agent that enhances the efficiency of the SearchProducts method.
306
308
307
-
Select the `SearchProducts` method in**ProductCatalog.cs** and use this prompt:
309
+
Select the **SearchProducts** method in**ProductCatalog.cs** and use this prompt:
308
310
309
311
```text
310
312
Refactor the SearchProducts method to eliminate performance bottlenecks. Optimize the search algorithm and remove unnecessary delays while maintaining search functionality.
311
313
```
312
314
313
315
Apply GitHub Copilot's suggestions to implement:
314
316
315
-
- Efficient string matching algorithms
316
-
- Parallel processing for multiple search criteria
317
-
- Optimized cache key generation
317
+
- Efficient string matching algorithms.
318
+
- Parallel processing for multiple search criteria.
319
+
- Optimized cache key generation.
318
320
319
-
1. Improve OrderProcessor performance for order calculations.
321
+
1. Assign a task to the agent that improves the performance of the CalculateOrderTotal method in the OrderProcessor class.
320
322
321
-
Open **OrderProcessor.cs** and select the `CalculateOrderTotal` method. Submit this prompt:
323
+
Open **OrderProcessor.cs** and select the **CalculateOrderTotal** method. Submit this prompt:
322
324
323
325
```text
324
326
Optimize the CalculateOrderTotal method to reduce redundant product lookups and improve calculation performance. Consider batch operations and caching strategies.
325
327
```
326
328
327
329
Implement the suggested improvements, which should include:
328
330
329
-
- Batch product retrieval to eliminate N+1 query patterns
330
-
- Cached product information during order processing
331
-
- Optimized tax and shipping calculations
331
+
- Batch product retrieval to eliminate N+1 query patterns.
332
+
- Cached product information during order processing.
333
+
- Optimized tax and shipping calculations.
332
334
333
335
1. Optimize the FinalizeOrderAsync method.
334
336
335
-
Select the `FinalizeOrderAsync` method in **OrderProcessor.cs** and use this prompt:
337
+
Select the **FinalizeOrderAsync** method in **OrderProcessor.cs** and use this prompt:
336
338
337
339
```text
338
340
Refactor the FinalizeOrderAsync method to improve async performance. Focus on parallel processing where possible and optimizing await patterns.
@@ -346,7 +348,7 @@ Use the following steps to complete this task:
346
348
347
349
1. Enhance InventoryManager batch operations.
348
350
349
-
Open **InventoryManager.cs** and select the `UpdateStockLevels` method. Use this prompt:
351
+
Open **InventoryManager.cs** and select the **UpdateStockLevels** method. Use this prompt:
350
352
351
353
```text
352
354
Optimize the UpdateStockLevels method to support batch operations and reduce individual update overhead. Implement efficient logging and remove unnecessary delays.
0 commit comments