json 2.7.2 → 2.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDL +22 -0
- data/CHANGES.md +37 -17
- data/LEGAL +60 -0
- data/README.md +13 -165
- data/ext/json/ext/fbuffer/fbuffer.h +21 -62
- data/ext/json/ext/generator/extconf.rb +8 -2
- data/ext/json/ext/generator/generator.c +457 -659
- data/ext/json/ext/generator/generator.h +16 -64
- data/ext/json/ext/parser/extconf.rb +3 -1
- data/ext/json/ext/parser/parser.c +279 -253
- data/ext/json/ext/parser/parser.h +4 -40
- data/ext/json/ext/parser/parser.rl +208 -182
- data/json.gemspec +42 -49
- data/lib/json/add/bigdecimal.rb +1 -1
- data/lib/json/add/complex.rb +1 -1
- data/lib/json/add/core.rb +1 -1
- data/lib/json/add/date.rb +1 -1
- data/lib/json/add/date_time.rb +1 -1
- data/lib/json/add/exception.rb +1 -1
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/range.rb +1 -1
- data/lib/json/add/rational.rb +1 -1
- data/lib/json/add/regexp.rb +1 -1
- data/lib/json/add/struct.rb +1 -1
- data/lib/json/add/symbol.rb +1 -2
- data/lib/json/add/time.rb +3 -10
- data/lib/json/common.rb +74 -43
- data/lib/json/ext/generator/state.rb +135 -0
- data/lib/json/ext.rb +18 -5
- data/lib/json/generic_object.rb +1 -1
- data/lib/json/pure/generator.rb +89 -22
- data/lib/json/pure/parser.rb +13 -19
- data/lib/json/pure.rb +1 -0
- data/lib/json/version.rb +3 -7
- data/lib/json.rb +1 -1
- metadata +17 -15
- data/ext/json/ext/generator/depend +0 -1
- data/ext/json/ext/parser/depend +0 -1
- data/ext/json/extconf.rb +0 -3
- /data/{LICENSE → COPYING} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1500b32611dd205778d21f8175a6e587c85d8090e9861c6ab5c2bbdc8cc7b107
|
4
|
+
data.tar.gz: 7bccf2b0c350f282b152f0e85addedb62d596c83a5347afa4205bb025f1dd24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf52a3ae9060dcebbc0febfde70aba86d718dd0545eb55da4f25e7fffa3bacbaff82e56656c189f6d7ffd25093c9a5967085864ce1db921dcb0e9cc92c9b299f
|
7
|
+
data.tar.gz: 55d5e7da5ff1dee20b3a48e08d7a8e389fe8cd4a1f6569ca84d0a59f0e84085fb5af3e2a6721f76ea7dfd860bdbdc8844e7464572191be0c816bf0522036edd0
|
data/BSDL
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
### 2024-10-24 (2.7.3)
|
4
|
+
|
5
|
+
* Numerous performance optimizations in `JSON.generate` and `JSON.dump` (up to 2 times faster).
|
6
|
+
* Limit the size of ParserError exception messages, only include up to 32 bytes of the unparseable source.
|
7
|
+
* Fix json-pure's `Object#to_json` to accept non state arguments
|
8
|
+
* Fix multiline comment support in `json-pure`.
|
9
|
+
* Fix `JSON.parse` to no longer mutate the argument encoding when passed an ASCII-8BIT string.
|
10
|
+
* Fix `String#to_json` to raise on invalid encoding in `json-pure`.
|
11
|
+
* Delete code that was based on CVTUTF.
|
12
|
+
* Use the pure-Ruby generator on TruffleRuby.
|
13
|
+
* Fix `strict` mode in `json-pure` to not break on Integer.
|
14
|
+
|
15
|
+
### 2024-04-04 (2.7.2)
|
16
|
+
|
17
|
+
* Use rb_sym2str instead of SYM2ID #561
|
18
|
+
* Fix memory leak when exception is raised during JSON generation #574
|
19
|
+
* Remove references to "19" methods in JRuby #576
|
20
|
+
* Make OpenStruct support as optional by @hsbt in #565
|
21
|
+
* Autoload JSON::GenericObject to avoid require ostruct warning in Ruby 3.4 #577
|
22
|
+
* Warn to install ostruct if json couldn't load it by @hsbt #578
|
23
|
+
|
3
24
|
### 2023-12-05 (2.7.1)
|
4
25
|
|
5
26
|
* JSON.dump: handle unenclosed hashes regression #554
|
@@ -168,7 +189,7 @@
|
|
168
189
|
* Remove Rubinius exception since transcoding should be working now.
|
169
190
|
|
170
191
|
## 2013-05-13 (1.8.0)
|
171
|
-
* Fix https://github.com/
|
192
|
+
* Fix https://github.com/ruby/json/issues/162 reported by Marc-Andre
|
172
193
|
Lafortune <github_rocks@marc-andre.ca>. Thanks!
|
173
194
|
* Applied patches by Yui NARUSE <naruse@airemix.jp> to suppress warning with
|
174
195
|
-Wchar-subscripts and better validate UTF-8 strings.
|
@@ -188,7 +209,7 @@
|
|
188
209
|
JSON::GenericObject.json_creatable = true
|
189
210
|
as well.
|
190
211
|
* Remove useless assert in fbuffer implementation.
|
191
|
-
* Apply patch attached to https://github.com/
|
212
|
+
* Apply patch attached to https://github.com/ruby/json/issues#issue/155
|
192
213
|
provided by John Shahid <jvshahid@gmail.com>, Thx!
|
193
214
|
* Add license information to rubygems spec data, reported by Jordi Massaguer Pla <jmassaguerpla@suse.de>.
|
194
215
|
* Improve documentation, thx to Zachary Scott <zachary@zacharyscott.net>.
|
@@ -202,7 +223,7 @@
|
|
202
223
|
* Fix compilation of extension on older rubies.
|
203
224
|
|
204
225
|
## 2012-07-26 (1.7.4)
|
205
|
-
* Fix compilation problem on AIX, see https://github.com/
|
226
|
+
* Fix compilation problem on AIX, see https://github.com/ruby/json/issues/142
|
206
227
|
|
207
228
|
## 2012-05-12 (1.7.3)
|
208
229
|
* Work around Rubinius encoding issues using iconv for conversion instead.
|
@@ -224,9 +245,9 @@
|
|
224
245
|
* Propagate src encoding to values made from it (fixes 1.9 mode converting
|
225
246
|
everything to ascii-8bit; harmless for 1.8 mode too) (Thomas E. Enebo
|
226
247
|
<tom.enebo@gmail.com>), should fix
|
227
|
-
https://github.com/
|
228
|
-
* Fix https://github.com/
|
229
|
-
* Fix https://github.com/
|
248
|
+
https://github.com/ruby/json/issues#issue/119.
|
249
|
+
* Fix https://github.com/ruby/json/issues#issue/124 Thx to Jason Hutchens.
|
250
|
+
* Fix https://github.com/ruby/json/issues#issue/117
|
230
251
|
|
231
252
|
## 2012-01-15 (1.6.5)
|
232
253
|
* Vit Ondruch <v.ondruch@tiscali.cz> reported a bug that shows up when using
|
@@ -253,7 +274,7 @@
|
|
253
274
|
patch go to Josh Partlow (jpartlow@github).
|
254
275
|
* Improve parsing speed for JSON numbers (integers and floats) in a similar way to
|
255
276
|
what Evan Phoenix <evan@phx.io> suggested in:
|
256
|
-
https://github.com/
|
277
|
+
https://github.com/ruby/json/pull/103
|
257
278
|
|
258
279
|
## 2011-09-18 (1.6.1)
|
259
280
|
* Using -target 1.5 to force Java bits to compile with 1.5.
|
@@ -266,15 +287,14 @@
|
|
266
287
|
* Fix memory leak when used from multiple JRuby. (Patch by
|
267
288
|
jfirebaugh@github).
|
268
289
|
* Apply patch by Eric Wong <nocode@yhbt.net> that fixes garbage collection problem
|
269
|
-
reported in https://github.com/
|
290
|
+
reported in https://github.com/ruby/json/issues/46.
|
270
291
|
* Add :quirks_mode option to parser and generator.
|
271
292
|
* Add support for Rational and Complex number additions via json/add/complex
|
272
293
|
and json/add/rational requires.
|
273
294
|
|
274
295
|
## 2011-06-20 (1.5.3)
|
275
296
|
* Alias State#configure method as State#merge to increase duck type synonymy with Hash.
|
276
|
-
|
277
|
-
the new way.
|
297
|
+
* Add `as_json` methods in json/add/core, so rails can create its json objects the new way.
|
278
298
|
|
279
299
|
## 2011-05-11 (1.5.2)
|
280
300
|
* Apply documentation patch by Cory Monty <cory.monty@gmail.com>.
|
@@ -285,7 +305,7 @@
|
|
285
305
|
|
286
306
|
## 2011-01-24 (1.5.1)
|
287
307
|
* Made rake-compiler build a fat binary gem. This should fix issue
|
288
|
-
https://github.com/
|
308
|
+
https://github.com/ruby/json/issues#issue/54.
|
289
309
|
|
290
310
|
## 2011-01-22 (1.5.0)
|
291
311
|
* Included Java source codes for the Jruby extension made by Daniel Luz
|
@@ -295,7 +315,7 @@
|
|
295
315
|
reported by Riley Goodside.
|
296
316
|
|
297
317
|
## 2010-08-09 (1.4.6)
|
298
|
-
* Fixed oversight reported in http://github.com/
|
318
|
+
* Fixed oversight reported in http://github.com/ruby/json/issues/closed#issue/23,
|
299
319
|
always create a new object from the state prototype.
|
300
320
|
* Made pure and ext api more similar again.
|
301
321
|
|
@@ -305,12 +325,12 @@
|
|
305
325
|
argument.
|
306
326
|
* Some fixes in the state objects and additional tests.
|
307
327
|
## 2010-08-06 (1.4.4)
|
308
|
-
* Fixes build problem for rubinius under OS X, http://github.com/
|
309
|
-
* Fixes crashes described in http://github.com/
|
310
|
-
http://github.com/
|
328
|
+
* Fixes build problem for rubinius under OS X, http://github.com/ruby/json/issues/closed#issue/25
|
329
|
+
* Fixes crashes described in http://github.com/ruby/json/issues/closed#issue/21 and
|
330
|
+
http://github.com/ruby/json/issues/closed#issue/23
|
311
331
|
## 2010-05-05 (1.4.3)
|
312
332
|
* Fixed some test assertions, from Ruby r27587 and r27590, patch by nobu.
|
313
|
-
* Fixed issue http://github.com/
|
333
|
+
* Fixed issue http://github.com/ruby/json/issues/#issue/20 reported by
|
314
334
|
electronicwhisper@github. Thx!
|
315
335
|
|
316
336
|
## 2010-04-26 (1.4.2)
|
@@ -332,7 +352,7 @@
|
|
332
352
|
* Extension should at least be compatible with MRI, YARV and Rubinius.
|
333
353
|
|
334
354
|
## 2010-04-07 (1.2.4)
|
335
|
-
*
|
355
|
+
* Trigger const_missing callback to make Rails' dynamic class loading work.
|
336
356
|
|
337
357
|
## 2010-03-11 (1.2.3)
|
338
358
|
* Added a `State#[]` method which returns an attribute's value in order to
|
data/LEGAL
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- rdoc -*-
|
2
|
+
|
3
|
+
= LEGAL NOTICE INFORMATION
|
4
|
+
--------------------------
|
5
|
+
|
6
|
+
All the files in this distribution are covered under either the Ruby's
|
7
|
+
license (see the file COPYING) or public-domain except some files
|
8
|
+
mentioned below.
|
9
|
+
|
10
|
+
== MIT License
|
11
|
+
>>>
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
a copy of this software and associated documentation files (the
|
14
|
+
"Software"), to deal in the Software without restriction, including
|
15
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be
|
21
|
+
included in all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
|
31
|
+
== Old-style BSD license
|
32
|
+
>>>
|
33
|
+
Redistribution and use in source and binary forms, with or without
|
34
|
+
modification, are permitted provided that the following conditions
|
35
|
+
are met:
|
36
|
+
1. Redistributions of source code must retain the above copyright
|
37
|
+
notice, this list of conditions and the following disclaimer.
|
38
|
+
2. Redistributions in binary form must reproduce the above copyright
|
39
|
+
notice, this list of conditions and the following disclaimer in the
|
40
|
+
documentation and/or other materials provided with the distribution.
|
41
|
+
3. Neither the name of the University nor the names of its contributors
|
42
|
+
may be used to endorse or promote products derived from this software
|
43
|
+
without specific prior written permission.
|
44
|
+
|
45
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
46
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
47
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
48
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
49
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
50
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
51
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
52
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
53
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
54
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
55
|
+
SUCH DAMAGE.
|
56
|
+
|
57
|
+
IMPORTANT NOTE::
|
58
|
+
|
59
|
+
From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
|
60
|
+
paragraph 3 above is now null and void.
|
data/README.md
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# JSON implementation for Ruby
|
2
2
|
|
3
|
-
[![CI](https://github.com/
|
3
|
+
[![CI](https://github.com/ruby/json/actions/workflows/ci.yml/badge.svg)](https://github.com/ruby/json/actions/workflows/ci.yml)
|
4
4
|
|
5
5
|
## Description
|
6
6
|
|
7
|
-
This is
|
8
|
-
http://www.ietf.org/rfc/rfc7159.txt .
|
9
|
-
will be two variants available:
|
7
|
+
This is an implementation of the JSON specification according to RFC 7159
|
8
|
+
http://www.ietf.org/rfc/rfc7159.txt . There is two variants available:
|
10
9
|
|
11
|
-
* A pure ruby variant, that relies on the
|
12
|
-
|
10
|
+
* A pure ruby variant, that relies on the `strscan` extensions, which is
|
11
|
+
part of the ruby standard library.
|
13
12
|
* The quite a bit faster native extension variant, which is in parts
|
14
|
-
implemented in C or Java and comes with
|
15
|
-
|
13
|
+
implemented in C or Java and comes with a parser generated by the [Ragel]
|
14
|
+
state machine compiler.
|
16
15
|
|
17
16
|
Both variants of the JSON generator generate UTF-8 character sequences by
|
18
17
|
default. If an :ascii\_only option with a true value is given, they escape all
|
@@ -32,45 +31,19 @@ It's recommended to use the extension variant of JSON, because it's faster than
|
|
32
31
|
the pure ruby variant. If you cannot build it on your system, you can settle
|
33
32
|
for the latter.
|
34
33
|
|
35
|
-
|
34
|
+
Install the gem and add to the application's Gemfile by executing:
|
36
35
|
|
37
|
-
|
38
|
-
# rake install
|
39
|
-
```
|
40
|
-
|
41
|
-
The above command will build the extensions and install them on your system.
|
42
|
-
|
43
|
-
```
|
44
|
-
# rake install_pure
|
45
|
-
```
|
46
|
-
|
47
|
-
or
|
48
|
-
|
49
|
-
```
|
50
|
-
# ruby install.rb
|
51
|
-
```
|
36
|
+
$ bundle add json
|
52
37
|
|
53
|
-
|
38
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
54
39
|
|
55
|
-
|
40
|
+
$ gem install json
|
56
41
|
|
57
|
-
```
|
58
|
-
# gem install json
|
59
|
-
```
|
60
|
-
|
61
|
-
instead, to install the newest JSON version.
|
62
42
|
|
63
43
|
There is also a pure ruby json only variant of the gem, that can be installed
|
64
44
|
with:
|
65
45
|
|
66
|
-
|
67
|
-
# gem install json_pure
|
68
|
-
```
|
69
|
-
|
70
|
-
## Compiling the extensions yourself
|
71
|
-
|
72
|
-
If you want to create the `parser.c` file from its `parser.rl` file or draw nice
|
73
|
-
graphviz images of the state machines, you need [Ragel].
|
46
|
+
$ gem install json_pure
|
74
47
|
|
75
48
|
## Usage
|
76
49
|
|
@@ -254,136 +227,11 @@ There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
|
|
254
227
|
`pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
|
255
228
|
the `pp` library's `pp` methods.
|
256
229
|
|
257
|
-
The script `tools/server.rb` contains a small example if you want to test, how
|
258
|
-
receiving a JSON object from a webrick server in your browser with the
|
259
|
-
JavaScript prototype library http://www.prototypejs.org works.
|
260
|
-
|
261
|
-
## Speed Comparisons
|
262
|
-
|
263
|
-
I have created some benchmark results (see the benchmarks/data-p4-3Ghz
|
264
|
-
subdir of the package) for the JSON-parser to estimate the speed up in the C
|
265
|
-
extension:
|
266
|
-
|
267
|
-
```
|
268
|
-
Comparing times (call_time_mean):
|
269
|
-
1 ParserBenchmarkExt#parser 900 repeats:
|
270
|
-
553.922304770 ( real) -> 21.500x
|
271
|
-
0.001805307
|
272
|
-
2 ParserBenchmarkYAML#parser 1000 repeats:
|
273
|
-
224.513358139 ( real) -> 8.714x
|
274
|
-
0.004454078
|
275
|
-
3 ParserBenchmarkPure#parser 1000 repeats:
|
276
|
-
26.755020642 ( real) -> 1.038x
|
277
|
-
0.037376163
|
278
|
-
4 ParserBenchmarkRails#parser 1000 repeats:
|
279
|
-
25.763381731 ( real) -> 1.000x
|
280
|
-
0.038814780
|
281
|
-
calls/sec ( time) -> speed covers
|
282
|
-
secs/call
|
283
|
-
```
|
284
|
-
|
285
|
-
In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
|
286
|
-
compatible JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
|
287
|
-
`ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
|
288
|
-
input first to YAML and then uses the YAML-parser, the conversion seems to
|
289
|
-
slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
|
290
|
-
|
291
|
-
If you look at the benchmark data you can see that this is mostly caused by
|
292
|
-
the frequent high outliers - the median of the Rails-parser runs is still
|
293
|
-
overall smaller than the median of the `JSON::Pure::Parser` runs:
|
294
|
-
|
295
|
-
```
|
296
|
-
Comparing times (call_time_median):
|
297
|
-
1 ParserBenchmarkExt#parser 900 repeats:
|
298
|
-
800.592479481 ( real) -> 26.936x
|
299
|
-
0.001249075
|
300
|
-
2 ParserBenchmarkYAML#parser 1000 repeats:
|
301
|
-
271.002390644 ( real) -> 9.118x
|
302
|
-
0.003690004
|
303
|
-
3 ParserBenchmarkRails#parser 1000 repeats:
|
304
|
-
30.227910865 ( real) -> 1.017x
|
305
|
-
0.033082008
|
306
|
-
4 ParserBenchmarkPure#parser 1000 repeats:
|
307
|
-
29.722384421 ( real) -> 1.000x
|
308
|
-
0.033644676
|
309
|
-
calls/sec ( time) -> speed covers
|
310
|
-
secs/call
|
311
|
-
```
|
312
|
-
|
313
|
-
I have benchmarked the `JSON-Generator` as well. This generated a few more
|
314
|
-
values, because there are different modes that also influence the achieved
|
315
|
-
speed:
|
316
|
-
|
317
|
-
```
|
318
|
-
Comparing times (call_time_mean):
|
319
|
-
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
320
|
-
547.354332608 ( real) -> 15.090x
|
321
|
-
0.001826970
|
322
|
-
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
323
|
-
443.968212317 ( real) -> 12.240x
|
324
|
-
0.002252414
|
325
|
-
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
326
|
-
375.104545883 ( real) -> 10.341x
|
327
|
-
0.002665923
|
328
|
-
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
329
|
-
49.978706968 ( real) -> 1.378x
|
330
|
-
0.020008521
|
331
|
-
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
332
|
-
38.531868759 ( real) -> 1.062x
|
333
|
-
0.025952543
|
334
|
-
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
335
|
-
36.927649925 ( real) -> 1.018x 7 (>=3859)
|
336
|
-
0.027079979
|
337
|
-
7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
338
|
-
36.272134441 ( real) -> 1.000x 6 (>=3859)
|
339
|
-
0.027569373
|
340
|
-
calls/sec ( time) -> speed covers
|
341
|
-
secs/call
|
342
|
-
```
|
343
|
-
|
344
|
-
In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
|
345
|
-
`JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
|
346
|
-
bit faster than the `generator_safe` and `generator_pretty` methods of the pure
|
347
|
-
variant but slower than the others.
|
348
|
-
|
349
|
-
To achieve the fastest JSON document output, you can use the `fast_generate`
|
350
|
-
method. Beware, that this will disable the checking for circular Ruby data
|
351
|
-
structures, which may cause JSON to go into an infinite loop.
|
352
|
-
|
353
|
-
Here are the median comparisons for completeness' sake:
|
354
|
-
|
355
|
-
```
|
356
|
-
Comparing times (call_time_median):
|
357
|
-
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
358
|
-
708.258020939 ( real) -> 16.547x
|
359
|
-
0.001411915
|
360
|
-
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
361
|
-
569.105020353 ( real) -> 13.296x
|
362
|
-
0.001757145
|
363
|
-
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
364
|
-
482.825371244 ( real) -> 11.280x
|
365
|
-
0.002071142
|
366
|
-
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
367
|
-
62.717626652 ( real) -> 1.465x
|
368
|
-
0.015944481
|
369
|
-
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
370
|
-
43.965681162 ( real) -> 1.027x
|
371
|
-
0.022745013
|
372
|
-
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
373
|
-
43.929073409 ( real) -> 1.026x 7 (>=3859)
|
374
|
-
0.022763968
|
375
|
-
7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
376
|
-
42.802514491 ( real) -> 1.000x 6 (>=3859)
|
377
|
-
0.023363113
|
378
|
-
calls/sec ( time) -> speed covers
|
379
|
-
secs/call
|
380
|
-
```
|
381
|
-
|
382
230
|
## Development
|
383
231
|
|
384
232
|
### Release
|
385
233
|
|
386
|
-
Update the json.
|
234
|
+
Update the `lib/json/version.rb` file.
|
387
235
|
|
388
236
|
```
|
389
237
|
rbenv shell 2.6.5
|
@@ -1,47 +1,8 @@
|
|
1
|
-
|
2
1
|
#ifndef _FBUFFER_H_
|
3
2
|
#define _FBUFFER_H_
|
4
3
|
|
5
4
|
#include "ruby.h"
|
6
|
-
|
7
|
-
#ifndef RHASH_SIZE
|
8
|
-
#define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
|
9
|
-
#endif
|
10
|
-
|
11
|
-
#ifndef RFLOAT_VALUE
|
12
|
-
#define RFLOAT_VALUE(val) (RFLOAT(val)->value)
|
13
|
-
#endif
|
14
|
-
|
15
|
-
#ifndef RARRAY_LEN
|
16
|
-
#define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
|
17
|
-
#endif
|
18
|
-
#ifndef RSTRING_PTR
|
19
|
-
#define RSTRING_PTR(string) RSTRING(string)->ptr
|
20
|
-
#endif
|
21
|
-
#ifndef RSTRING_LEN
|
22
|
-
#define RSTRING_LEN(string) RSTRING(string)->len
|
23
|
-
#endif
|
24
|
-
|
25
|
-
#ifdef PRIsVALUE
|
26
|
-
# define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
|
27
|
-
# define RB_OBJ_STRING(obj) (obj)
|
28
|
-
#else
|
29
|
-
# define PRIsVALUE "s"
|
30
|
-
# define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
|
31
|
-
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
|
32
|
-
#endif
|
33
|
-
|
34
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
35
5
|
#include "ruby/encoding.h"
|
36
|
-
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
|
37
|
-
#else
|
38
|
-
#define FORCE_UTF8(obj)
|
39
|
-
#endif
|
40
|
-
|
41
|
-
/* We don't need to guard objects for rbx, so let's do nothing at all. */
|
42
|
-
#ifndef RB_GC_GUARD
|
43
|
-
#define RB_GC_GUARD(object)
|
44
|
-
#endif
|
45
6
|
|
46
7
|
typedef struct FBufferStruct {
|
47
8
|
unsigned long initial_length;
|
@@ -59,17 +20,22 @@ typedef struct FBufferStruct {
|
|
59
20
|
|
60
21
|
static FBuffer *fbuffer_alloc(unsigned long initial_length);
|
61
22
|
static void fbuffer_free(FBuffer *fb);
|
23
|
+
#ifndef JSON_GENERATOR
|
62
24
|
static void fbuffer_clear(FBuffer *fb);
|
25
|
+
#endif
|
63
26
|
static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len);
|
64
27
|
#ifdef JSON_GENERATOR
|
65
28
|
static void fbuffer_append_long(FBuffer *fb, long number);
|
66
29
|
#endif
|
67
30
|
static void fbuffer_append_char(FBuffer *fb, char newchr);
|
68
31
|
#ifdef JSON_GENERATOR
|
69
|
-
static FBuffer *fbuffer_dup(FBuffer *fb);
|
70
32
|
static VALUE fbuffer_to_s(FBuffer *fb);
|
71
33
|
#endif
|
72
34
|
|
35
|
+
#ifndef RB_UNLIKELY
|
36
|
+
#define RB_UNLIKELY(expr) expr
|
37
|
+
#endif
|
38
|
+
|
73
39
|
static FBuffer *fbuffer_alloc(unsigned long initial_length)
|
74
40
|
{
|
75
41
|
FBuffer *fb;
|
@@ -86,25 +52,29 @@ static void fbuffer_free(FBuffer *fb)
|
|
86
52
|
ruby_xfree(fb);
|
87
53
|
}
|
88
54
|
|
55
|
+
#ifndef JSON_GENERATOR
|
89
56
|
static void fbuffer_clear(FBuffer *fb)
|
90
57
|
{
|
91
58
|
fb->len = 0;
|
92
59
|
}
|
60
|
+
#endif
|
93
61
|
|
94
|
-
static void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
|
62
|
+
static inline void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
|
95
63
|
{
|
96
|
-
|
64
|
+
if (RB_UNLIKELY(requested > fb->capa - fb->len)) {
|
65
|
+
unsigned long required;
|
97
66
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
67
|
+
if (RB_UNLIKELY(!fb->ptr)) {
|
68
|
+
fb->ptr = ALLOC_N(char, fb->initial_length);
|
69
|
+
fb->capa = fb->initial_length;
|
70
|
+
}
|
102
71
|
|
103
|
-
|
72
|
+
for (required = fb->capa; requested > required - fb->len; required <<= 1);
|
104
73
|
|
105
|
-
|
106
|
-
|
107
|
-
|
74
|
+
if (required > fb->capa) {
|
75
|
+
REALLOC_N(fb->ptr, char, required);
|
76
|
+
fb->capa = required;
|
77
|
+
}
|
108
78
|
}
|
109
79
|
}
|
110
80
|
|
@@ -166,21 +136,10 @@ static void fbuffer_append_long(FBuffer *fb, long number)
|
|
166
136
|
fbuffer_append(fb, buf, len);
|
167
137
|
}
|
168
138
|
|
169
|
-
static FBuffer *fbuffer_dup(FBuffer *fb)
|
170
|
-
{
|
171
|
-
unsigned long len = fb->len;
|
172
|
-
FBuffer *result;
|
173
|
-
|
174
|
-
result = fbuffer_alloc(len);
|
175
|
-
fbuffer_append(result, FBUFFER_PAIR(fb));
|
176
|
-
return result;
|
177
|
-
}
|
178
|
-
|
179
139
|
static VALUE fbuffer_to_s(FBuffer *fb)
|
180
140
|
{
|
181
|
-
VALUE result =
|
141
|
+
VALUE result = rb_utf8_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
|
182
142
|
fbuffer_free(fb);
|
183
|
-
FORCE_UTF8(result);
|
184
143
|
return result;
|
185
144
|
}
|
186
145
|
#endif
|
@@ -1,4 +1,10 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
if RUBY_ENGINE == 'truffleruby'
|
4
|
+
# The pure-Ruby generator is faster on TruffleRuby, so skip compiling the generator extension
|
5
|
+
File.write('Makefile', dummy_makefile("").join)
|
6
|
+
else
|
7
|
+
append_cflags("-std=c99")
|
8
|
+
$defs << "-DJSON_GENERATOR"
|
9
|
+
create_makefile 'json/ext/generator'
|
10
|
+
end
|