A few years back I had to write a base view model which is not aware of the model that will be used with it as generic. Only thing that the base view model knows is that every model will definitely have a Name property. And I had to write all the logic to set the properties of this Model in the base only as it was common and we used to receive the property name(string) and value(object) from SignalR. I used reflection as I am not aware of the properties of Model’s used in child view models. Slowly as the number of child viewmodels increased and the list of object’s(Model’s) inside each child view model, I started seeing the problem. Then I clearly understood that reflection is the major reason for the performance issue.

Then after some thorough research, I did some benchmarks to see how much does reflection cost me vs using an interface and implementing those methods in every model and making it strongly typed and avoiding reflection.

Version 1:

I wrote a new simple interface.

public interface IObject
{
    bool SetValue(string propertyName, object value);
    object GetValue(string propertyName);
    T GetValue<T>(string propertyName); // I skipped the implementation of this in this post. Please find that in source code. 
}

and it’s implementation is like.

public class FooV1 : IObject
{
    public int Integer { get; set; } = int.MaxValue;
    public string String { get; set; } = "some random string";
    
    public object GetValue(string propertyName)
    {
        return propertyName switch
        {
            nameof(Integer) => Integer,
            nameof(String) => String,
            _ => null,
        };
    }

    public bool SetValue(string propertyName, object value)
    {
        switch (propertyName)
        {
            case nameof(Integer):
                {
                    Integer = (int)value;
                    return true;
                }
            case nameof(String):
                {
                    String = (string)value;
                    return true;
                }
            default:
                return false;
        }
    }
}

When I did the benchmarks for setting a value using reflection, I saw using an interface brought down the time taken to set a property to a min of 70% and max of 91%.

As this worked out very well, and I had too many model’s so I built our own source generator using a console app as I was using .NET6 where the source generators are still experimental. And this whole implementation brought down our app launch time from 60+ seconds to less than 20 seconds. Btw, the properties inside the Model used to change very rarely. So when they did, we used to run the generator again and copy the files. And we ensure these generated files should never be changed manually and named them something like Foo.g.cs which helps me review the PR’s easily from the team. And ofcourse, I wrote an API to return the properties and their metadata in the way that I need so that my generator can generate the classes for me.

Version 2: (Update on  16th March 2025)

Uses ReadOnlySpan<char> but same like V3.

Version 3: (Update on  22th March 2025)

I read in multiple blogs that .NET invested a lot in performance improvement using ReadOnlySpan over the years. I was wondering if we can still make this better. So I tried again with ChatGPT help. Now compared to V1, V2 had at least 40% improvement over V1.

Nothing changed in my interface. But the implementation changed a bit.

public class Foo : IObject
{
    public int Integer { get; set; } = int.MaxValue;
    public string String { get; set; } = "some random string";

}

And my implementation is like


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool SetValue(string propertyName, object value)
{
    switch (propertyName.Length)
    {
        case 6 when string.CompareOrdinal(propertyName, "String") == 0:
            String = (string)value;
            return true;
        case 7 when string.CompareOrdinal(propertyName, "Integer") == 0:
            Integer = (int)value;
            return true;
    }
    return false;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public object GetValue(string propertyName)
{
    return propertyName.Length switch
    {
        6 when string.CompareOrdinal(propertyName, "String") == 0 => String,
        7 when string.CompareOrdinal(propertyName, "Integer") == 0 => Integer,
        _ => Unsafe.NullRef<object>(),
    };
}

As I said, I took ChatGPT help, I am not 100% sure how MethodImpl helps.

Major benefits I saw are switch case speed was improved by 20% at least when I was checking the lenhth of the property name first.

Here are the benchmarks (Source Models)

  1. Reflection_Without_Cache
  2. Reflection_With_Cache
  3. V1 - use nameof(Integer) inside switch
  4. V2 - use case 8 when span.SequenceEqual("DateTime") inside switch
  5. V3 - use ` case 4 when string.CompareOrdinal(propertyName, “Guid”) == 0` inside switch

For some scenarios, V1 and V2 are better than V3. But ultimately V1, V2, V3 are found to be much faster than reflection.

.NET 8 only.


BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.3476)
Unknown processor
.NET SDK 9.0.201
  [Host]     : .NET 8.0.13 (8.0.1325.6609), X64 RyuJIT AVX2
  Job-WPGPLG : .NET 8.0.13 (8.0.1325.6609), X64 RyuJIT AVX2

OutlierMode=DontRemove  Runtime=.NET 8.0  

MethodCategoriesMeanErrorStdDevStdErrMedianMinQ1Q3MaxOp/sRatioMannWhitney(10%)RatioSDRankBaselineGen0Gen1AllocatedAlloc Ratio
NoReflection_V2_Set_DateTimeGet_DateTime4.5517 ns0.2983 ns0.8796 ns0.0880 ns4.2290 ns3.4317 ns3.8785 ns4.9696 ns7.8496 ns219,700,020.80.000Faster0.001No0.0019-24 B0.002
NoReflection_V3_Set_DateTimeGet_DateTime4.7152 ns0.2273 ns0.6703 ns0.0670 ns4.6290 ns3.4477 ns4.2965 ns5.0264 ns7.2109 ns212,080,656.20.000Faster0.001No0.0019-24 B0.002
NoReflection_V1_Set_DateTimeGet_DateTime4.7909 ns0.2835 ns0.8359 ns0.0836 ns4.5264 ns3.3833 ns4.2094 ns5.3136 ns7.4346 ns208,727,204.80.000Faster0.001No0.0019-24 B0.002
Reflection_With_Cache_Set_DateTimeGet_DateTime21.8594 ns0.6201 ns1.8284 ns0.1828 ns21.3681 ns19.6099 ns20.7650 ns22.1471 ns30.0197 ns45,746,892.20.000Faster0.002No0.0019-24 B0.002
Reflection_Without_Cache_Set_DateTimeGet_DateTime134,661.9640 ns2,691.1319 ns7,412.1594 ns790.1388 ns133,193.8232 ns123,581.5552 ns130,676.0071 ns136,705.8472 ns177,430.4810 ns7,426.01.003Baseline0.073Yes0.73240.48839869 B1.000
                     
NoReflection_V3_Set_DateTimeOffsetGet_DateTimeOffset3.7162 ns0.1290 ns0.2083 ns0.0357 ns3.7949 ns3.2027 ns3.5734 ns3.8436 ns4.0136 ns269,089,492.30.000Faster0.001No0.0025-32 B0.003
NoReflection_V2_Set_DateTimeOffsetGet_DateTimeOffset4.0179 ns0.1463 ns0.4313 ns0.0431 ns3.8755 ns3.5427 ns3.7683 ns4.1254 ns6.0838 ns248,887,791.90.000Faster0.001No0.0025-32 B0.003
NoReflection_V1_Set_DateTimeOffsetGet_DateTimeOffset4.1067 ns0.1277 ns0.1470 ns0.0329 ns4.0821 ns3.8588 ns4.0282 ns4.2195 ns4.3973 ns243,504,377.20.000Faster0.001No0.0025-32 B0.003
Reflection_With_Cache_Set_DateTimeOffsetGet_DateTimeOffset22.9583 ns0.4975 ns0.6642 ns0.1328 ns22.8489 ns21.5919 ns22.5537 ns23.3382 ns24.5150 ns43,557,325.10.000Faster0.002No0.0025-32 B0.003
Reflection_Without_Cache_Set_DateTimeOffsetGet_DateTimeOffset137,139.4918 ns2,729.6094 ns6,487.2061 ns792.5384 ns136,235.6445 ns125,979.3457 ns133,105.0781 ns139,492.0898 ns156,980.2246 ns7,291.81.002Baseline0.073Yes0.73240.48839877 B1.000
                     
NoReflection_V1_Set_DecimalGet_Decimal3.7811 ns0.1228 ns0.3035 ns0.0358 ns3.7175 ns3.3545 ns3.5838 ns3.8663 ns4.8348 ns264,470,348.30.000Faster0.001No0.0025-32 B0.003
NoReflection_V2_Set_DecimalGet_Decimal4.0014 ns0.1239 ns0.1695 ns0.0333 ns3.9680 ns3.7608 ns3.8577 ns4.1279 ns4.3559 ns249,914,466.00.000Faster0.001No0.0025-32 B0.003
NoReflection_V3_Set_DecimalGet_Decimal4.0153 ns0.1281 ns0.1258 ns0.0315 ns4.0288 ns3.7534 ns3.9167 ns4.1218 ns4.2130 ns249,045,715.40.000Faster0.001No0.0025-32 B0.003
Reflection_With_Cache_Set_DecimalGet_Decimal20.5950 ns0.4473 ns0.5657 ns0.1180 ns20.4532 ns19.7400 ns20.1383 ns21.0274 ns21.6487 ns48,555,358.90.000Faster0.002No0.0025-32 B0.003
Reflection_Without_Cache_Set_DecimalGet_Decimal134,489.7712 ns2,631.0768 ns4,538.4785 ns736.2384 ns133,503.2104 ns127,546.0693 ns131,537.1033 ns136,604.9133 ns146,288.9893 ns7,435.51.001Baseline0.053Yes0.73240.48839877 B1.000
                     
NoReflection_V3_Set_DoubleGet_Double3.5649 ns0.1177 ns0.1308 ns0.0300 ns3.5514 ns3.3009 ns3.4836 ns3.6701 ns3.8001 ns280,513,385.00.000Faster0.001No0.0019-24 B0.002
NoReflection_V1_Set_DoubleGet_Double3.6716 ns0.1213 ns0.3044 ns0.0354 ns3.6054 ns3.2118 ns3.4908 ns3.7530 ns5.0924 ns272,358,381.00.000Faster0.001No0.0019-24 B0.002
NoReflection_V2_Set_DoubleGet_Double3.7531 ns0.1216 ns0.1447 ns0.0316 ns3.7683 ns3.5128 ns3.6303 ns3.8475 ns4.0238 ns266,449,272.10.000Faster0.001No0.0019-24 B0.002
Reflection_With_Cache_Set_DoubleGet_Double19.2798 ns0.4345 ns0.5650 ns0.1153 ns19.1776 ns18.0503 ns18.9049 ns19.7031 ns20.4502 ns51,867,729.60.000Faster0.002No0.0019-24 B0.002
Reflection_Without_Cache_Set_DoubleGet_Double129,740.5649 ns2,579.6557 ns3,616.3173 ns695.9606 ns129,637.7808 ns119,660.0220 ns128,151.2939 ns131,464.3677 ns138,131.7017 ns7,707.71.001Baseline0.043Yes0.73240.48839869 B1.000
                     
NoReflection_V1_Set_GuidGet_Guid3.7056 ns0.1230 ns0.2341 ns0.0349 ns3.6541 ns3.3387 ns3.5241 ns3.8523 ns4.2413 ns269,862,033.10.000Faster0.001No0.0025-32 B0.003
NoReflection_V3_Set_GuidGet_Guid3.7767 ns0.1229 ns0.1262 ns0.0306 ns3.7678 ns3.5814 ns3.6889 ns3.8115 ns4.0256 ns264,779,728.00.000Faster0.001No0.0025-32 B0.003
NoReflection_V2_Set_GuidGet_Guid3.8309 ns0.1226 ns0.3231 ns0.0359 ns3.7543 ns3.3759 ns3.6551 ns3.9058 ns4.9528 ns261,034,235.70.000Faster0.001No0.0025-32 B0.003
Reflection_With_Cache_Set_GuidGet_Guid19.8743 ns0.4411 ns0.4126 ns0.1065 ns19.8063 ns19.3926 ns19.6436 ns20.0446 ns21.0902 ns50,316,263.30.000Faster0.002No0.0025-32 B0.003
Reflection_Without_Cache_Set_GuidGet_Guid135,491.5876 ns2,743.1428 ns8,088.2191 ns808.8219 ns133,703.3081 ns124,534.2773 ns130,160.0647 ns137,751.4526 ns171,266.7236 ns7,380.51.003Baseline0.083Yes0.73240.48839877 B1.000
                     
NoReflection_V2_Set_IntegerGet_Integer3.5274 ns0.1202 ns0.1235 ns0.0299 ns3.5408 ns3.2584 ns3.4917 ns3.6042 ns3.8026 ns283,492,711.10.000Faster0.001No0.0019-24 B0.002
NoReflection_V3_Set_IntegerGet_Integer3.7825 ns0.1513 ns0.4460 ns0.0446 ns3.6393 ns3.3081 ns3.5307 ns3.8380 ns5.3877 ns264,372,830.30.000Faster0.001No0.0019-24 B0.002
NoReflection_V1_Set_IntegerGet_Integer3.8396 ns0.1351 ns0.3982 ns0.0398 ns3.7218 ns3.3032 ns3.6317 ns3.8514 ns5.4046 ns260,442,978.20.000Faster0.001No0.0019-24 B0.002
Reflection_With_Cache_Set_IntegerGet_Integer19.0440 ns0.4303 ns0.6571 ns0.1180 ns18.8650 ns18.1617 ns18.5483 ns19.4110 ns20.6893 ns52,509,882.90.000Faster0.002No0.0019-24 B0.002
Reflection_Without_Cache_Set_IntegerGet_Integer126,710.4232 ns2,499.3397 ns2,337.8839 ns603.6390 ns126,187.4023 ns123,532.2754 ns125,077.6245 ns128,073.9624 ns131,795.9961 ns7,892.01.000Baseline0.033Yes0.73240.48839869 B1.000
                     
NoReflection_V3_Set_StringGet_String0.0782 ns0.0466 ns0.0654 ns0.0126 ns0.0658 ns0.0000 ns0.0329 ns0.0962 ns0.2702 ns12,781,470,817.80.000Faster0.001No---0.00
NoReflection_V1_Set_StringGet_String0.2158 ns0.0503 ns0.0470 ns0.0121 ns0.2134 ns0.1162 ns0.1817 ns0.2613 ns0.2772 ns4,633,337,326.30.000Faster0.002No---0.00
NoReflection_V2_Set_StringGet_String0.2952 ns0.0601 ns0.1772 ns0.0177 ns0.2639 ns0.0904 ns0.1982 ns0.3172 ns1.1964 ns3,387,405,487.90.000Faster0.002No---0.00
Reflection_With_Cache_Set_StringGet_String15.6339 ns0.3505 ns0.4173 ns0.0911 ns15.6530 ns14.7821 ns15.3859 ns15.8924 ns16.4015 ns63,963,611.20.000Faster0.003No---0.00
Reflection_Without_Cache_Set_StringGet_String118,884.1680 ns2,586.5382 ns7,626.4669 ns762.6467 ns117,331.6162 ns111,331.3843 ns115,293.2861 ns120,267.0593 ns164,474.0601 ns8,411.51.003Baseline0.084Yes0.73240.48839845 B1.00
                     
NoReflection_V2_Get_DateTimeSet_DateTime2.8906 ns0.1041 ns0.3070 ns0.0307 ns2.8211 ns2.4469 ns2.6998 ns2.9995 ns4.0856 ns345,950,412.40.000Faster0.001No0.0019-24 B0.002
NoReflection_V3_Get_DateTimeSet_DateTime3.1750 ns0.1230 ns0.3625 ns0.0363 ns3.0762 ns2.8220 ns2.9759 ns3.2142 ns5.2140 ns314,963,146.10.000Faster0.002No0.0019-24 B0.002
NoReflection_V1_Get_DateTimeSet_DateTime5.2101 ns0.1803 ns0.5315 ns0.0531 ns5.0712 ns4.7095 ns4.9405 ns5.2395 ns8.2705 ns191,934,799.50.000Faster0.003No0.0019-24 B0.002
Reflection_With_Cache_Get_DateTimeSet_DateTime20.1890 ns0.4316 ns0.4037 ns0.1042 ns20.1776 ns19.6258 ns19.9135 ns20.4161 ns21.2007 ns49,532,045.70.000Faster0.004No0.0019-24 B0.002
Reflection_Without_Cache_Get_DateTimeSet_DateTime130,268.6307 ns2,597.7659 ns3,555.8516 ns697.3599 ns129,806.9580 ns124,744.2383 ns127,990.5579 ns132,300.6104 ns139,301.9287 ns7,676.41.001Baseline0.045Yes0.73240.48839869 B1.000
                     
NoReflection_V3_Get_DateTimeOffsetSet_DateTimeOffset3.0432 ns0.0960 ns0.1495 ns0.0264 ns3.1056 ns2.6898 ns2.9241 ns3.1514 ns3.2748 ns328,598,384.20.000Faster0.001No0.0025-32 B0.003
NoReflection_V2_Get_DateTimeOffsetSet_DateTimeOffset3.4683 ns0.0951 ns0.1096 ns0.0245 ns3.4397 ns3.3095 ns3.4105 ns3.5001 ns3.7342 ns288,328,118.20.000Faster0.002No0.0025-32 B0.003
Reflection_With_Cache_Get_DateTimeOffsetSet_DateTimeOffset23.8058 ns0.5025 ns1.2972 ns0.1469 ns23.4511 ns22.2782 ns23.0489 ns24.1136 ns29.5990 ns42,006,550.40.000Faster0.003No0.0025-32 B0.003
NoReflection_V1_Get_DateTimeOffsetSet_DateTimeOffset317.5865 ns6.3141 ns6.4841 ns1.5726 ns316.9801 ns306.2600 ns313.6859 ns323.1713 ns331.3868 ns3,148,748.20.002Faster0.004No0.0086-112 B0.011
Reflection_Without_Cache_Get_DateTimeOffsetSet_DateTimeOffset137,027.1792 ns2,730.2798 ns7,877.4822 ns803.9922 ns134,812.8906 ns124,553.1372 ns131,685.6934 ns139,315.8020 ns162,161.8774 ns7,297.81.003Baseline0.085Yes0.73240.48839877 B1.000
                     
NoReflection_V1_Get_DecimalSet_Decimal6.2628 ns0.1259 ns0.1178 ns0.0304 ns6.2240 ns6.1194 ns6.1524 ns6.3526 ns6.4604 ns159,673,612.80.000Faster0.001No0.0025-32 B0.003
NoReflection_V3_Get_DecimalSet_Decimal6.3059 ns0.1663 ns0.4904 ns0.0490 ns6.1845 ns5.7768 ns6.0436 ns6.4363 ns8.9667 ns158,580,496.60.000Faster0.001No0.0025-32 B0.003
NoReflection_V2_Get_DecimalSet_Decimal6.4429 ns0.3363 ns0.9915 ns0.0992 ns6.2171 ns5.6030 ns6.0364 ns6.3887 ns11.3938 ns155,210,034.80.000Faster0.001No0.0025-32 B0.003
Reflection_With_Cache_Get_DecimalSet_Decimal20.3052 ns0.4326 ns1.2201 ns0.1272 ns19.9694 ns18.3997 ns19.6820 ns20.5008 ns26.4400 ns49,248,471.10.000Faster0.002No0.0025-32 B0.003
Reflection_Without_Cache_Get_DecimalSet_Decimal137,143.1565 ns2,936.4919 ns8,658.3132 ns865.8313 ns135,118.4082 ns127,400.3540 ns132,145.0684 ns138,664.0930 ns173,335.6812 ns7,291.71.004Baseline0.083Yes0.73240.48839877 B1.000
                     
NoReflection_V1_Get_DoubleSet_Double2.6467 ns0.0812 ns0.2223 ns0.0238 ns2.5704 ns2.3163 ns2.5037 ns2.7248 ns3.3613 ns377,831,827.00.000Faster0.001No0.0019-24 B0.002
NoReflection_V2_Get_DoubleSet_Double2.9580 ns0.0971 ns0.2862 ns0.0286 ns2.8888 ns2.6219 ns2.7903 ns3.0067 ns4.1613 ns338,070,224.40.000Faster0.002No0.0019-24 B0.002
NoReflection_V3_Get_DoubleSet_Double3.1474 ns0.1019 ns0.3005 ns0.0300 ns3.0606 ns2.7716 ns2.9684 ns3.1827 ns4.2605 ns317,723,917.80.000Faster0.003No0.0019-24 B0.002
Reflection_With_Cache_Get_DoubleSet_Double20.4806 ns0.7390 ns2.1791 ns0.2179 ns19.6909 ns18.3152 ns19.3207 ns20.9957 ns29.3660 ns48,826,672.00.000Faster0.004No0.0019-24 B0.002
Reflection_Without_Cache_Get_DoubleSet_Double129,202.4500 ns2,531.6658 ns4,298.9609 ns706.7448 ns129,334.4727 ns121,357.5684 ns125,726.1230 ns131,337.5000 ns141,482.3975 ns7,739.81.001Baseline0.055Yes0.73240.48839869 B1.000
                     
NoReflection_V3_Get_GuidSet_Guid2.8940 ns0.0859 ns0.2534 ns0.0253 ns2.8206 ns2.6164 ns2.7380 ns2.9600 ns3.8257 ns345,543,118.10.000Faster0.001No0.0025-32 B0.003
NoReflection_V2_Get_GuidSet_Guid3.3165 ns0.0944 ns0.2279 ns0.0274 ns3.2616 ns3.0444 ns3.1606 ns3.4025 ns4.1803 ns301,523,790.60.000Faster0.002No0.0025-32 B0.003
Reflection_With_Cache_Get_GuidSet_Guid20.7118 ns1.2184 ns3.5926 ns0.3593 ns19.4997 ns16.0189 ns18.9454 ns21.6103 ns39.6250 ns48,281,562.70.000Faster0.003No0.0025-32 B0.003
NoReflection_V1_Get_GuidSet_Guid30.0480 ns0.6153 ns0.6839 ns0.1569 ns29.9435 ns28.9659 ns29.6475 ns30.5377 ns31.2570 ns33,280,091.60.000Faster0.004No0.0102-128 B0.013
Reflection_Without_Cache_Get_GuidSet_Guid132,874.0360 ns2,604.8178 ns3,977.8322 ns714.4398 ns132,995.6787 ns124,531.3721 ns130,434.8755 ns134,868.2983 ns141,678.2715 ns7,525.91.001Baseline0.045Yes0.73240.48839877 B1.000
                     
NoReflection_V1_Get_IntegerSet_Integer2.7217 ns0.0670 ns0.0627 ns0.0162 ns2.7441 ns2.6047 ns2.6768 ns2.7695 ns2.8092 ns367,420,135.50.000Faster0.001No0.0019-24 B0.002
NoReflection_V2_Get_IntegerSet_Integer3.0827 ns0.0984 ns0.2902 ns0.0290 ns3.0070 ns2.7975 ns2.9216 ns3.1258 ns4.2512 ns324,387,748.70.000Faster0.002No0.0019-24 B0.002
NoReflection_V3_Get_IntegerSet_Integer3.9375 ns0.3712 ns1.0945 ns0.1095 ns3.5521 ns2.8889 ns3.2500 ns4.1203 ns8.0053 ns253,965,374.50.000Faster0.003No0.0019-24 B0.002
Reflection_With_Cache_Get_IntegerSet_Integer30.9542 ns2.6882 ns7.9263 ns0.7926 ns28.5827 ns18.2969 ns23.8744 ns38.9046 ns47.9196 ns32,305,785.40.000Faster0.004No0.0019-24 B0.002
Reflection_Without_Cache_Get_IntegerSet_Integer142,474.0798 ns6,921.4765 ns20,408.1310 ns2,040.8131 ns133,723.9502 ns123,583.1543 ns128,822.6746 ns150,420.3979 ns228,735.4248 ns7,018.81.017Baseline0.195Yes0.73240.48839869 B1.000
                     
NoReflection_V1_Get_StringSet_String0.2627 ns0.0649 ns0.1914 ns0.0191 ns0.2061 ns0.0540 ns0.1455 ns0.3112 ns1.1851 ns3,805,982,355.80.000Faster0.001No---0.00
NoReflection_V3_Get_StringSet_String0.4023 ns0.0363 ns0.1041 ns0.0107 ns0.4101 ns0.2508 ns0.3003 ns0.4764 ns0.8205 ns2,485,524,201.20.000Faster0.002No---0.00
NoReflection_V2_Get_StringSet_String0.4799 ns0.0348 ns0.0965 ns0.0102 ns0.4739 ns0.3357 ns0.3822 ns0.5736 ns0.6416 ns2,083,978,900.80.000Faster0.003No---0.00
Reflection_With_Cache_Get_StringSet_String18.1842 ns0.5745 ns1.6938 ns0.1694 ns17.8831 ns15.4772 ns17.0659 ns18.6517 ns24.9986 ns54,992,887.40.000Faster0.004No---0.00
Reflection_Without_Cache_Get_StringSet_String142,514.6326 ns14,749.9085 ns43,490.4413 ns4,349.0441 ns126,482.3364 ns108,507.4951 ns121,651.1719 ns137,077.9968 ns343,677.6611 ns7,016.81.057Baseline0.385Yes0.73240.48839845 B1.00

This is one of my best performance improvements I have ever done. This might not be significant in many places  but for situations like mine, this saves a lot of time during run time.

Note: I tried to use this logic in System.Text.Json but couldn’t beat it though it was using reflection. It was highly optimized and I gave up.


Created At08-Mar-2024 08:00 PM +0000
Modified At16-Mar-2025 06:00 PM +0000
Deployed At23-Jul-2025 03:26 AM +0000
Santosh Jallapuram on Stack Overvflow