Commit 0ba5c7e
committed
Optimize Dispatcher message processing logic
Refactor the `Dispatcher` class to improve performance and reduce thread pool scheduling overhead:
- Replace `Task.Run` with direct async calls to `SendMessageAsync` for message sending.
- Ensure `batchSize` has a minimum value of 1 and preallocate the `tasks` list for efficiency.
- Add a conditional check to invoke `Task.WhenAll` only when tasks exist.
- Simplify non-parallel send logic by reusing `SendMessageAsync`.
- Introduce the `SendMessageAsync` method to encapsulate message sending, handle exceptions, and log errors.
- Use `.ConfigureAwait(false)` consistently for asynchronous calls.
These changes enhance maintainability, readability, and performance by reducing redundant code and optimizing asynchronous operations.1 parent f4c74d9 commit 0ba5c7e
1 file changed
+26
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
253 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
254 | 256 | | |
255 | 257 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 258 | + | |
269 | 259 | | |
270 | 260 | | |
271 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
272 | 265 | | |
273 | 266 | | |
274 | 267 | | |
275 | 268 | | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
| 269 | + | |
285 | 270 | | |
286 | 271 | | |
287 | 272 | | |
| |||
292 | 277 | | |
293 | 278 | | |
294 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
295 | 296 | | |
296 | 297 | | |
297 | 298 | | |
| |||
0 commit comments