exceptionless / Exceptionless.Net

Exceptionless clients for the .NET platform
https://exceptionless.com
Other
554 stars 142 forks source link

Faster Snake Case Naming #256

Closed benaadams closed 3 years ago

benaadams commented 3 years ago

Up to x3.5 faster snake casing for Json properties via caching; also dumps the cache at Gen2.

Move to ConversionCached approach; less allocations and much faster conversion (also incorporates the StringBuilderCached for new strings)

Method Word Mean Ratio Gen 0 Allocated
SnakeCase A 37.22 ns 1.00 0.0255 120 B
StringBuilderCached A 35.24 ns 0.94 0.0051 24 B
ConversionCached A 18.99 ns 0.51 - -
SnakeCase InnerException 109.54 ns 1.00 0.0374 176 B
StringBuilderCached InnerException 101.12 ns 0.92 0.0118 56 B
ConversionCached InnerException 23.95 ns 0.22 - -
SnakeCase Message 65.09 ns 1.00 0.0322 152 B
StringBuilderCached Message 59.97 ns 0.92 0.0085 40 B
ConversionCached Message 22.86 ns 0.35 - -
SnakeCase StackTrace 91.76 ns 1.00 0.0340 160 B
StringBuilderCached StackTrace 82.57 ns 0.90 0.0101 48 B
ConversionCached StackTrace 22.07 ns 0.24 - -
SnakeCase property 55.52 ns 1.00 0.0322 152 B
StringBuilderCached property 55.52 ns 1.00 0.0085 40 B
ConversionCached property 21.86 ns 0.39 - -
ejsmith commented 3 years ago

I guess this is highly likely to hit cache as well since JSON names are repeated so much, eh? What kind of overall difference does this make?

ejsmith commented 3 years ago

@benaadams my concern with this PR is that it's pretty hard core and I'd just like to see that it's worth it outside of the microbenchmark of just snake casing strings. I'm pretty sure this is going to get called a ton in the real world and it would get a lot of cache hits because JSON has a lot of repeated strings, but it would be really nice to see an overall benchmark of using the client to send a bunch of events and seeing how changes like this and hopefully many more in the future impact the client overall. Thoughts?

benaadams commented 3 years ago

@ejsmith sorry have rebuilding my machine so am re-setting up; should be able to provide more feedback after

benaadams commented 3 years ago

I'm pretty sure this is going to get called a ton in the real world and it would get a lot of cache hits because JSON has a lot of repeated strings

So for a vanilla config every logged exception generates these 88 strings as part of JSON serilization (probably should also add tests to make sure its generating the same)

Type => type
Source => source
Date => date
Tags => tags
Message => message
Geo => geo
Value => value
Count => count
Data => data
ReferenceId => reference_id
Modules => modules
Message => message
Type => type
Code => code
Data => data
Inner => inner
StackTrace => stack_trace
TargetMethod => target_method
ModuleId => module_id
Name => name
Version => version
IsEntry => is_entry
CreatedDate => created_date
ModifiedDate => modified_date
Data => data
Message => message
Type => type
Code => code
Data => data
Inner => inner
StackTrace => stack_trace
TargetMethod => target_method
FileName => file_name
LineNumber => line_number
Column => column
IsSignatureTarget => is_signature_target
DeclaringNamespace => declaring_namespace
DeclaringType => declaring_type
Name => name
ModuleId => module_id
Data => data
GenericArguments => generic_arguments
Parameters => parameters
Name => name
Type => type
TypeNamespace => type_namespace
Data => data
GenericArguments => generic_arguments
IsSignatureTarget => is_signature_target
DeclaringNamespace => declaring_namespace
DeclaringType => declaring_type
Name => name
ModuleId => module_id
Data => data
GenericArguments => generic_arguments
Parameters => parameters
ProcessorCount => processor_count
TotalPhysicalMemory => total_physical_memory
AvailablePhysicalMemory => available_physical_memory
CommandLine => command_line
ProcessName => process_name
ProcessId => process_id
ProcessMemorySize => process_memory_size
ThreadName => thread_name
ThreadId => thread_id
Architecture => architecture
OSName => o_s_name
OSVersion => o_s_version
IpAddress => ip_address
MachineName => machine_name
InstallId => install_id
RuntimeVersion => runtime_version
Data => data
Identity => identity
Name => name
Data => data
UserAgent => user_agent
HttpMethod => http_method
IsSecure => is_secure
Host => host
Port => port
Path => path
Referrer => referrer
ClientIpAddress => client_ip_address
Cookies => cookies
PostData => post_data
QueryString => query_string
Data => data
benaadams commented 3 years ago

Saying that; there's a bigger item I also want to add and it will use the same GC mechanism, so will add that first and come back with measurements

benaadams commented 3 years ago

Hmm.. will get back to you, closing for now