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