Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed temporary array allocations for properties #1948

Merged
merged 3 commits into from Oct 3, 2023

Conversation

epeshk
Copy link
Contributor

@epeshk epeshk commented Aug 21, 2023

Similar to #1779, but uses on-stack allocation instead of pooling.

@epeshk
Copy link
Contributor Author

epeshk commented Aug 21, 2023

I'm not sure it's worth (and possible) to optimize the default ILogger interface implementation before params ReadOnlySpan<T> support is released in C#.

https://github.com/dotnet/csharplang/blob/main/proposals/params-span.md

@nblumhardt
Copy link
Member

Thanks - this looks like a nice option 👍 - may take some more time to review.

@nblumhardt
Copy link
Member

I think this is the way to go - looks like CI produced some failures, though.

{
if (messageTemplateParameters == null || messageTemplateParameters.Length == 0)
if (messageTemplateParameters.Length == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth including a few quick speculative tests to check that removing the == null test here is safe even when callers without strict null checking enabled call various logger methods, e.g.:

[Fact]
public void NullMessageTemplateParametersDoNotBreakBinding()
{
    var log = new LoggerConfiguration().WriteTo.Sink(new CollectingSink()).CreateLogger();
    log.Information("test", (object?[]?) null);
    log.BindMessageTemplate("test", (object?[]?)null, out _, out _);
}

?

@nblumhardt nblumhardt merged commit d6e80e6 into serilog:dev Oct 3, 2023
1 check passed
@nblumhardt nblumhardt mentioned this pull request Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants