-Added missing XML documentation
-Fixed potential null reference error when getting attributes -Performance documentation
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<topic id="Performance" revisionNumber="1">
|
||||
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<introduction>
|
||||
<para>Out of the box Json.NET is faster than DataContractJsonSerializer and JavaScriptSerializer.
|
||||
Here are some tips to make it go even faster.</para>
|
||||
</introduction>
|
||||
<section>
|
||||
<title>Optimize Memory Usage</title>
|
||||
<content>
|
||||
<para>To keep an application consistantly fast it is important to minimize the
|
||||
amount of time the .NET framework spends performing <externalLink>
|
||||
<linkText>garbage collection</linkText>
|
||||
<linkUri>http://msdn.microsoft.com/en-us/library/ms973837.aspx</linkUri>
|
||||
<linkTarget>_blank</linkTarget>
|
||||
</externalLink>.
|
||||
Allocating too many objects, or allocating very large objects can slow down or even
|
||||
halt an application while garbage collection is in progress.
|
||||
</para>
|
||||
<para>To minimize memory usage and the number of objects allocated Json.NET supports
|
||||
serializing and deserializing directly to a stream. Reading or writing JSON a piece at a time instead of having
|
||||
the entire JSON string loaded into memory is especially important when working with JSON
|
||||
documents greater than 85kb in size to avoid the JSON string ending up in the <externalLink>
|
||||
<linkText>large object heap</linkText>
|
||||
<linkUri>http://msdn.microsoft.com/en-us/magazine/cc534993.aspx</linkUri>
|
||||
<linkTarget>_blank</linkTarget>
|
||||
</externalLink>.</para>
|
||||
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeString" title="Deserialize String" />
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeStream" title="Deserialize Stream" />
|
||||
|
||||
</content>
|
||||
</section>
|
||||
<section>
|
||||
<title>JsonConverters</title>
|
||||
<content>
|
||||
<para>Passing a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> to SerializeObject or DeserializeObject provides a simple way to completely
|
||||
change how an object is serialized. There is however a small overhead; the CanConvert method is called for every
|
||||
type to check whether serialization should be handled by that JsonConverter.</para>
|
||||
<para>There are a couple of ways to continue to use JsonConverters without any overhead. The simplest way
|
||||
is to specify the JsonConverter using the <codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>. This attribute tells the serializer
|
||||
to always use that converter when serializing and deserializing the type, without the check.</para>
|
||||
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterAttribute" title="Use JsonConverter with JsonConverterAttribute" />
|
||||
|
||||
<para>If the class you want to convert isn't your own and you're unable to use an attribute a JsonConverter can still be used by
|
||||
creating your own <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>.</para>
|
||||
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
|
||||
|
||||
<para>The IContractResolver in the example above will set all DateTimes to use the JavaScriptDateConverter.</para>
|
||||
</content>
|
||||
</section>
|
||||
<section>
|
||||
<title>Manually Serialize</title>
|
||||
<content>
|
||||
<para>The absolute fastest way to read and write JSON is to use JsonTextReader and JsonTextWriter directly. Using a reader or writer
|
||||
directly skips any of the overhead from a serializer such as reflection.</para>
|
||||
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="ReaderWriter" title="Manually serialize using JsonTextWriter" />
|
||||
|
||||
<para>If performance is important and you don't mind more code to get it then this is your best choice.</para>
|
||||
</content>
|
||||
</section>
|
||||
<section>
|
||||
<title>Benchmarks</title>
|
||||
<content>
|
||||
|
||||
<mediaLink>
|
||||
<image class="image" xlink:href="performance" mimeType="image/png" width="643" height="345" />
|
||||
<summary>Json.NET Performance</summary>
|
||||
</mediaLink>
|
||||
|
||||
</content>
|
||||
</section>
|
||||
<relatedTopics>
|
||||
<codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
|
||||
<codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
|
||||
<codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>
|
||||
<codeEntityReference>T:Newtonsoft.Json.JsonTextWriter</codeEntityReference>
|
||||
<codeEntityReference>T:Newtonsoft.Json.JsonTextReader</codeEntityReference>
|
||||
</relatedTopics>
|
||||
</developerConceptualDocument>
|
||||
</topic>
|
||||
+2
-1
@@ -21,7 +21,8 @@
|
||||
<Topic id="QueryingLINQtoJSON" visible="True" title="Querying JSON with LINQ" />
|
||||
<Topic id="SelectToken" visible="True" title="Querying JSON with SelectToken" />
|
||||
</Topic>
|
||||
<Topic id="JsonSchema" visible="True" isSelected="true" title="Validating JSON" />
|
||||
<Topic id="Performance" visible="True" isSelected="true" title="Performance" />
|
||||
<Topic id="JsonSchema" visible="True" title="Validating JSON" />
|
||||
<Topic id="ReadingWritingJSON" visible="True" title="Basic Reading and Writing JSON" />
|
||||
<Topic id="ConvertingJSONandXML" visible="True" title="Converting between JSON and XML" />
|
||||
</Topics>
|
||||
@@ -141,6 +141,7 @@
|
||||
<None Include="ContractResolver.aml" />
|
||||
<None Include="ConvertingJSONandXML.aml" />
|
||||
<None Include="CreatingLINQtoJSON.aml" />
|
||||
<None Include="Performance.aml" />
|
||||
<None Include="JsonSchema.aml" />
|
||||
<None Include="JsonSchema.aml" />
|
||||
<None Include="ParsingLINQtoJSON.aml" />
|
||||
@@ -165,6 +166,10 @@
|
||||
<ContentLayout Include="doc.content" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="performance.png">
|
||||
<ImageId>performance</ImageId>
|
||||
<AlternateText>performance</AlternateText>
|
||||
</Image>
|
||||
<Image Include="logo.jpg">
|
||||
<ImageId>logo</ImageId>
|
||||
<AlternateText>logo</AlternateText>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
Reference in New Issue
Block a user