-
Notifications
You must be signed in to change notification settings - Fork 866
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
perf: Optimize JToken to Dictionary conversion performance #9096
perf: Optimize JToken to Dictionary conversion performance #9096
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #9096 +/- ##
==========================================
- Coverage 77.57% 77.57% -0.01%
==========================================
Files 592 592
Lines 24608 24616 +8
==========================================
+ Hits 19090 19096 +6
- Misses 5518 5520 +2
☔ View full report in Codecov by Sentry. |
case JTokenType.Object: | ||
return ConvertJObjectToDictionary((JObject)jToken); | ||
default: | ||
if (jToken is JValue jValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why not also cast here?
if (jToken is JValue jValue) | |
return ((JValue)jToken).Value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why not also cast here?
There is some types that derived fromJToken
but not JValue. (e.g. JContainer, JProperty)
(Thought these types should not be passed to this function)
* perf: optimize jToken conversion performance * fix: fix problems that may cause infinite loop * fix: add unit tests for code coverage
What's included in this PR
ConvertToObjectHelper.ConvertJObjectToObject
method performance.AggressiveOptimization
attribute.Background
When running Visual Studio profiler.
Sometimes
ConvertJObjectToObject
method is reported as Hot Path.And this method is called about
64702
times when running docfx tosamples/seed
projecft.It seems
jObject.ToObject<Dictionary<string, object>>()
call can be safely removed.Because
JObject
already implementedIDictionary<string,JToken>
interface implicitly.Rewrite code from
To