~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/Newtonsoft.Json/Doc/Performance.aml

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="utf-8"?>
 
2
<topic id="Performance" revisionNumber="1">
 
3
  <developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
 
4
    <introduction>
 
5
      <para>Out of the box Json.NET is faster than DataContractJsonSerializer and JavaScriptSerializer.
 
6
      Here are some tips to make it go even faster.</para>
 
7
    </introduction>
 
8
    <section>
 
9
      <title>Optimize Memory Usage</title>
 
10
      <content>
 
11
        <para>To keep an application consistantly fast it is important to minimize the
 
12
        amount of time the .NET framework spends performing <externalLink>
 
13
<linkText>garbage collection</linkText>
 
14
<linkUri>http://msdn.microsoft.com/en-us/library/ms973837.aspx</linkUri>
 
15
<linkTarget>_blank</linkTarget>
 
16
</externalLink>.
 
17
        Allocating too many objects, or allocating very large objects can slow down or even
 
18
        halt an application while garbage collection is in progress.
 
19
        </para>
 
20
        <para>To minimize memory usage and the number of objects allocated Json.NET supports
 
21
        serializing and deserializing directly to a stream. Reading or writing JSON a piece at a time instead of having
 
22
        the entire JSON string loaded into memory is especially important when working with JSON
 
23
        documents greater than 85kb in size to avoid the JSON string ending up in the <externalLink>
 
24
<linkText>large object heap</linkText>
 
25
<linkUri>http://msdn.microsoft.com/en-us/magazine/cc534993.aspx</linkUri>
 
26
<linkTarget>_blank</linkTarget>
 
27
</externalLink>.</para>
 
28
 
 
29
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeString" title="Deserialize String" />
 
30
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeStream" title="Deserialize Stream" />
 
31
        
 
32
      </content>
 
33
    </section>
 
34
    <section>
 
35
      <title>JsonConverters</title>
 
36
      <content>
 
37
        <para>Passing a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> to SerializeObject or DeserializeObject provides a simple way to completely
 
38
        change how an object is serialized. There is however a small overhead; the CanConvert method is called for every
 
39
        value to check whether serialization should be handled by that JsonConverter.</para>
 
40
        <para>There are a couple of ways to continue to use JsonConverters without any overhead. The simplest way
 
41
        is to specify the JsonConverter using the <codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>. This attribute tells the serializer
 
42
        to always use that converter when serializing and deserializing the type, without the check.</para>
 
43
 
 
44
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterAttribute" title="Use JsonConverter with JsonConverterAttribute" />
 
45
 
 
46
        <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
 
47
        creating your own <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>.</para>
 
48
        
 
49
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
 
50
 
 
51
        <para>The IContractResolver in the example above will set all DateTimes to use the JavaScriptDateConverter.</para>        
 
52
      </content>
 
53
    </section>
 
54
    <section>
 
55
      <title>Manually Serialize</title>
 
56
      <content>
 
57
        <para>The absolute fastest way to read and write JSON is to use JsonTextReader/JsonTextWriter directly to manually serialize types.
 
58
        Using a reader or writer directly skips any of the overhead from a serializer such as reflection.</para>
 
59
        
 
60
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="ReaderWriter" title="Manually serialize using JsonTextWriter" />
 
61
 
 
62
        <para>If performance is important and you don't mind more code to get it then this is your best choice. Read more about using JsonReader/JsonWriter here:
 
63
        <externalLink>
 
64
        <linkText>Basic Reading and Writing JSON</linkText>
 
65
        <linkUri>ReadingWritingJSON.aml</linkUri>
 
66
        <linkTarget>_self</linkTarget>
 
67
      </externalLink>
 
68
        
 
69
        </para>
 
70
      </content>
 
71
    </section>
 
72
    <section>
 
73
      <title>Benchmarks</title>
 
74
      <content>
 
75
        
 
76
        <mediaLink>
 
77
      <image class="image" xlink:href="performance" mimeType="image/png" width="643" height="345" />
 
78
      <summary>Json.NET Performance</summary>
 
79
        </mediaLink>
 
80
        
 
81
      </content>
 
82
    </section>
 
83
    <relatedTopics>
 
84
      <codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
 
85
      <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
 
86
      <codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>
 
87
      <codeEntityReference>T:Newtonsoft.Json.JsonTextWriter</codeEntityReference>
 
88
      <codeEntityReference>T:Newtonsoft.Json.JsonTextReader</codeEntityReference>
 
89
    </relatedTopics>
 
90
  </developerConceptualDocument>
 
91
</topic>
 
 
b'\\ No newline at end of file'