-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Phase one logger optimisations (#2503)
This PR dramatically reduces the overhead of scoped logging, even for scenarios where the configured log level verbosity was low (e.g., Warning). The most critical improvement is caching scoped loggers within Spans, Traces, and Errors. We lose convenience in no longer having the span ID in the scope, but it's generally available from the Span argument. Previously, a new `ScopedLogger` was created for every span and transaction, and a new `ConditionalWeakTable` was also allocated. Due to the use of Finalisers on the CWT, this had an even more significant GC impact. We now maintain a cache of scoped loggers (of which there are relatively few). The ID creation for the Spans has been switched to `ActivitySpanId.CreateRandom().ToString()` from the MS diagnostics library, as this has been more heavily optimised than our original version and achieves the same goal. In `Tracer.End()`, we used an `Assertion` with a large interpolated string. This was being interpolated for each transaction as the `Assertion` path was enabled. However, the condition we assert is generally not met. Therefore, we now check this manually to only create the message if we are in an invalid state. I've also switched two structs to record structs, as these were used as keys in dictionaries and ended up being boxed due to a lack of `IEquality` implementations. These are phase one of optimisations for the logging implementation and address the general production scenario of using a less verbose log level. ### Profiling Profiling was achieved using a .NET 9 ASP.NET Core minimal API project with 20 concurrent connections and 100,000 requests. **Before Memory Profile** ![image](https://github.com/user-attachments/assets/6ba52339-dc4e-44a0-811d-039c9807c0fb) **After Memory Profile** ![image](https://github.com/user-attachments/assets/22a8fdcc-3cab-4b83-bd27-b6107f849899) **Before Top Retained** ![image](https://github.com/user-attachments/assets/348c837e-a910-4220-8a60-e12b4fd3f961) **After Top Retained** ![image](https://github.com/user-attachments/assets/d7a31e7b-f5cf-419a-8eaa-ed4042a07470) Closes #2500
- Loading branch information
1 parent
efa86c4
commit 1adae59
Showing
11 changed files
with
139 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.