ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.pm
(Generate patch)

Comparing JSON-XS/XS.pm (file contents):
Revision 1.84 by root, Wed Mar 19 02:52:15 2008 UTC vs.
Revision 1.89 by root, Wed Mar 19 13:54:53 2008 UTC

938directly when available (so will be 100% compatible with it, including 938directly when available (so will be 100% compatible with it, including
939speed), or it uses JSON::PP, which is basically JSON::XS translated to 939speed), or it uses JSON::PP, which is basically JSON::XS translated to
940Pure Perl, which should be 100% compatible with JSON::XS, just a bit 940Pure Perl, which should be 100% compatible with JSON::XS, just a bit
941slower. 941slower.
942 942
943You cannot really lose by using this module. 943You cannot really lose by using this module, especially as it tries very
944hard to work even with ancient Perl versions, while JSON::XS does not.
944 945
945=item JSON 1.07 946=item JSON 1.07
946 947
947Slow (but very portable, as it is written in pure Perl). 948Slow (but very portable, as it is written in pure Perl).
948 949
1080It seems that JSON::XS is surprisingly fast, as shown in the following 1081It seems that JSON::XS is surprisingly fast, as shown in the following
1081tables. They have been generated with the help of the C<eg/bench> program 1082tables. They have been generated with the help of the C<eg/bench> program
1082in the JSON::XS distribution, to make it easy to compare on your own 1083in the JSON::XS distribution, to make it easy to compare on your own
1083system. 1084system.
1084 1085
1085First comes a comparison between various modules using a very short 1086First comes a comparison between various modules using
1086single-line JSON string: 1087a very short single-line JSON string (also available at
1088L<http://dist.schmorp.de/misc/json/short.json>).
1087 1089
1088 {"method": "handleMessage", "params": ["user1", "we were just talking"], \ 1090 {"method": "handleMessage", "params": ["user1", "we were just talking"], \
1089 "id": null, "array":[1,11,234,-5,1e5,1e7, true, false]} 1091 "id": null, "array":[1,11,234,-5,1e5,1e7, true, false]}
1090 1092
1091It shows the number of encodes/decodes per second (JSON::XS uses 1093It shows the number of encodes/decodes per second (JSON::XS uses
1110about three times faster on decoding, and over forty times faster 1112about three times faster on decoding, and over forty times faster
1111than JSON, even with pretty-printing and key sorting. It also compares 1113than JSON, even with pretty-printing and key sorting. It also compares
1112favourably to Storable for small amounts of data. 1114favourably to Storable for small amounts of data.
1113 1115
1114Using a longer test string (roughly 18KB, generated from Yahoo! Locals 1116Using a longer test string (roughly 18KB, generated from Yahoo! Locals
1115search API (http://nanoref.com/yahooapis/mgPdGg): 1117search API (L<http://dist.schmorp.de/misc/json/long.json>).
1116 1118
1117 module | encode | decode | 1119 module | encode | decode |
1118 -----------|------------|------------| 1120 -----------|------------|------------|
1119 JSON 1.x | 55.260 | 34.971 | 1121 JSON 1.x | 55.260 | 34.971 |
1120 JSON::DWIW | 825.228 | 1082.513 | 1122 JSON::DWIW | 825.228 | 1082.513 |
1162to free the temporary). If that is exceeded, the program crashes. To be 1164to free the temporary). If that is exceeded, the program crashes. To be
1163conservative, the default nesting limit is set to 512. If your process 1165conservative, the default nesting limit is set to 512. If your process
1164has a smaller stack, you should adjust this setting accordingly with the 1166has a smaller stack, you should adjust this setting accordingly with the
1165C<max_depth> method. 1167C<max_depth> method.
1166 1168
1167And last but least, something else could bomb you that I forgot to think 1169Something else could bomb you, too, that I forgot to think of. In that
1168of. In that case, you get to keep the pieces. I am always open for hints, 1170case, you get to keep the pieces. I am always open for hints, though...
1169though... 1171
1172Also keep in mind that JSON::XS might leak contents of your Perl data
1173structures in its error messages, so when you serialise sensitive
1174information you might want to make sure that exceptions thrown by JSON::XS
1175will not end up in front of untrusted eyes.
1170 1176
1171If you are using JSON::XS to return packets to consumption 1177If you are using JSON::XS to return packets to consumption
1172by JavaScript scripts in a browser you should have a look at 1178by JavaScript scripts in a browser you should have a look at
1173L<http://jpsykes.com/47/practical-csrf-and-json-security> to see whether 1179L<http://jpsykes.com/47/practical-csrf-and-json-security> to see whether
1174you are vulnerable to some common attack vectors (which really are browser 1180you are vulnerable to some common attack vectors (which really are browser

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines