efcore / EFCore.NamingConventions

Entity Framework Core plugin to apply naming conventions to table and column names (e.g. snake_case)
Apache License 2.0
738 stars 74 forks source link

SnakeCaseNameRewriter: use stack memory (ValueStringBuilder) instead of StringBuilder #172

Closed gfoidl closed 1 year ago

gfoidl commented 1 year ago

In RewriteName there's always an allocation of https://github.com/efcore/EFCore.NamingConventions/blob/7f07dcce613ba5f67c92ec4d3357c14b461db79e/EFCore.NamingConventions/Internal/SnakeCaseNameRewriter.cs#L21

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 1 year ago

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.

gfoidl commented 1 year ago

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.