-
Notifications
You must be signed in to change notification settings - Fork 245
LoggerExtensions performance concerns #523
Comments
The zero allocation pattern is demonstrated in KestrelTrace.cs |
OK, so there are two extremes. Many allocations with What about some faster ILogger extensions? |
+1 on this. |
@benaadams @strohhut I actually didn't know about the |
Assigning to @BrennanConroy for investigation. cc @mikeharder |
You can also easily avoid unneeded allocations by using
|
Yeah, that's obvious. But who wants to do that (four to five lines for every logging statement, remember a closing brace should be followed by a blank line under most circumstances)? |
People that want to avoid a performance hit. We do it all over the framework. We also use LoggerMessage. These are all valid options we should document. What does the "what about some faster ILoggerExtensions" suggestion? Is that something concrete? Do you have ideas ok how to make it better? |
@davidfowl see the original post, simply providing some generic overloads to prevent the allocation of the params array in most cases would help - it's standard practice in both logging packages and other APIs... |
Let me dig up the PR where we decided against this change before. Making the extension methods check is enabled by default makes the peformancd worse when the caller checks as well. That was part of the original push back against doing so. |
Note that there are two separate proposals in the original post:
The two are definitely unrelated, I personally feel the first is much more needed than the second. |
@davidfowl You are saying that checking But checking |
Performance numbers would definitely help this discussion. Here's the old PR:
The problem with the extension methods that check for you is that ends up being the default. If you want to check IsEnabled yourself, you end up paying that |
We have a bug on docs to increase our documentation of the other logging patterns: dotnet/AspNetCore.Docs#2810 Moving this to the discussion milestone until something we want to actually implement falls out of it. |
We are closing this issue because no further action is planned for this issue. If you still have any issues or questions, please log a new issue with any additional details that you have. |
Say the log level is warning and I have the following in my code:
This creates a params array and a
FormattedLogValues
and boxing from int to object will occur although nothing will be logged.Wouldn't it make more sense to provide some overloads for typical amounts of arguments like
The text was updated successfully, but these errors were encountered: