efcore/EFCore.NamingConventions

SnakeCaseNameRewriter: use stack memory (ValueStringBuilder) instead of StringBuilder

Closed this issue · 2 comments

In RewriteName there's always an allocation of

var builder = new StringBuilder(name.Length + Math.Min(2, name.Length / 5));

As most names will be short that allocation(s)* could be avoided by using a stack-allocated char-buffer or a solution like ValueStringBuilder (copy & paste from dotnet/runtime-repo).

Is this something that you'd like me to try out in a PR?

* StringBuilder itself and the internal chunk(s) used by the SB

roji commented

The naming convention plugin is generally very non-perf-sensitive; it's only invoked when setting up the model, which occurs once on program startup (or even at design-time if you're using EF compiled models). So I wouldn't go into too much optimization here - especially if it makes things more complex or includes assumptions on name lengths etc. Let me know if you think that's worthwhile.

it's only invoked when setting up the model

Ah, I had a wrong assumption then. Thought it's used more often. Thanks for that info.
So no need to optimize this.