-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Investigate perf improvements for the built-in JsonNamingPolicy (SnakeCase) for DictionaryKeyPolicy #31486
Comments
Out of curiosity, could you run benchmarks only for |
I did, previously :) public class ConvertNamePerfComparison
{
JsonNamingPolicy _camelPolicy;
JsonSnakeCaseNamingPolicy _snakePolicy;
[Params("ID", "url", "URL", "THIS IS SPARTA", "IsCIA", "iPhone", "IPhone", "xml2json", "already_snake_case", "Hi!! This is text. Time to test.", "IsJSONProperty", "ABCDEFGHIJKLMNOP")]
public string InputString { get; set; }
[GlobalSetup]
public void Setup()
{
_camelPolicy = JsonNamingPolicy.CamelCase;
_snakePolicy = new JsonSnakeCaseNamingPolicy();
}
[BenchmarkCategory(Categories.CoreFX, Categories.JSON)]
[Benchmark (Baseline =true)]
public string Camel()
{
return _camelPolicy.ConvertName(InputString);
}
[BenchmarkCategory(Categories.CoreFX, Categories.JSON)]
[Benchmark]
public string Snake()
{
return _snakePolicy.ConvertName(InputString);
}
} BenchmarkDotNet=v0.11.5.1159-nightly, OS=Windows 10.0.18362
Intel Core i7-6700 CPU 3.40GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=3.1.100-preview1-014459
[Host] : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), X64 RyuJIT
Job-PHLPOC : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), X64 RyuJIT
PowerPlanMode=00000000-0000-0000-0000-000000000000 IterationTime=250.0000 ms MaxIterationCount=10
MinIterationCount=5 WarmupCount=1
|
Thanks, will take a look at it, but only starting next week. |
@ahsonkhan Probably it could be made faster by eliminating nullable types which I introduced to clarify the logic. |
I wonder - dotnet/corefx#41354 is not merged (Although a lot of effort has been spent there |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of the experimental issue cleanup initiative we are currently trialing in a limited number of areas. Please share any feedback you might have in the linked issue. |
This issue will now be closed since it had been marked |
One option to reduce the allocations could be to use
ValueStringBuilder
(see dotnet/corefx#41354 (comment)), though that doesn't help the throughput too much. It might be possible to re-implement the algorithm inConvertName
to be faster. Another idea might be to special case the first character to simplify some of the conditions within the loop (likecurrentIndex > 0
).The text was updated successfully, but these errors were encountered: