| Age | Commit message (Collapse) | Author |
|
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
|
|
https://github.com/ruby/json/commit/b240bde402
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
|
|
Avoid needless hash allocations and such that degrade performance
significantly on micro-benchmarks.
|
|
https://github.com/ruby/json/commit/e2e9936047
|
|
If we assume that most of the time the `opts` hash is small
it's faster to go over the provided keys with a `case` than
to test all possible keys one by one.
Before:
```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 156.832k i/100ms
oj 209.769k i/100ms
rapidjson 162.922k i/100ms
Calculating -------------------------------------
json 1.599M (± 2.5%) i/s (625.34 ns/i) - 7.998M in 5.005110s
oj 2.137M (± 1.5%) i/s (467.99 ns/i) - 10.698M in 5.007806s
rapidjson 1.677M (± 3.5%) i/s (596.31 ns/i) - 8.472M in 5.059515s
Comparison:
json: 1599141.2 i/s
oj: 2136785.3 i/s - 1.34x faster
rapidjson: 1676977.2 i/s - same-ish: difference falls within error
== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 216.464k i/100ms
oj 661.328k i/100ms
rapidjson 324.434k i/100ms
Calculating -------------------------------------
json 2.301M (± 1.7%) i/s (434.57 ns/i) - 11.689M in 5.081278s
oj 7.244M (± 1.2%) i/s (138.05 ns/i) - 36.373M in 5.021985s
rapidjson 3.323M (± 2.9%) i/s (300.96 ns/i) - 16.871M in 5.081696s
Comparison:
json: 2301142.2 i/s
oj: 7243770.3 i/s - 3.15x faster
rapidjson: 3322673.0 i/s - 1.44x faster
```
After:
```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 168.087k i/100ms
oj 208.872k i/100ms
rapidjson 149.909k i/100ms
Calculating -------------------------------------
json 1.761M (± 1.1%) i/s (567.90 ns/i) - 8.909M in 5.059794s
oj 2.144M (± 0.9%) i/s (466.37 ns/i) - 10.861M in 5.065903s
rapidjson 1.692M (± 1.7%) i/s (591.04 ns/i) - 8.545M in 5.051808s
Comparison:
json: 1760868.2 i/s
oj: 2144205.9 i/s - 1.22x faster
rapidjson: 1691941.1 i/s - 1.04x slower
== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 242.957k i/100ms
oj 675.217k i/100ms
rapidjson 355.040k i/100ms
Calculating -------------------------------------
json 2.569M (± 1.5%) i/s (389.22 ns/i) - 12.877M in 5.013095s
oj 7.128M (± 2.3%) i/s (140.30 ns/i) - 35.787M in 5.023594s
rapidjson 3.656M (± 3.1%) i/s (273.50 ns/i) - 18.462M in 5.054558s
Comparison:
json: 2569217.5 i/s
oj: 7127705.6 i/s - 2.77x faster
rapidjson: 3656285.0 i/s - 1.42x faster
```
|
|
This helps very marginally with allocation speed.
https://github.com/ruby/json/commit/25db79dfaa
|
|
`JSON.dump` looks terrible on micro-benchmarks because the way it
handles arguments is quite allocation heavy compared to the actual
JSON generation work.
Profiling the `small hash` benchmarked show 14% of time spent in `Array#compact`
and `34%` time spent in `JSON::Ext::GeneratorState.new`. Only `41%` in the
actual `generate` function.
By micro-optimizing `JSON.dump`, it can look much better:
Before:
```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 91.687k i/100ms
oj 205.309k i/100ms
rapidjson 161.648k i/100ms
Calculating -------------------------------------
json 941.965k (± 1.4%) i/s (1.06 μs/i) - 4.768M in 5.062573s
oj 2.138M (± 1.2%) i/s (467.82 ns/i) - 10.881M in 5.091254s
rapidjson 1.678M (± 1.9%) i/s (596.04 ns/i) - 8.406M in 5.011931s
Comparison:
json: 941964.8 i/s
oj: 2137586.5 i/s - 2.27x faster
rapidjson: 1677737.1 i/s - 1.78x faster
== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 141.737k i/100ms
oj 676.871k i/100ms
rapidjson 373.266k i/100ms
Calculating -------------------------------------
json 1.491M (± 1.0%) i/s (670.78 ns/i) - 7.512M in 5.039463s
oj 7.226M (± 1.4%) i/s (138.39 ns/i) - 36.551M in 5.059475s
rapidjson 3.729M (± 2.2%) i/s (268.15 ns/i) - 18.663M in 5.007182s
Comparison:
json: 1490798.2 i/s
oj: 7225766.2 i/s - 4.85x faster
rapidjson: 3729192.2 i/s - 2.50x faster
```
After:
```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 156.832k i/100ms
oj 209.769k i/100ms
rapidjson 162.922k i/100ms
Calculating -------------------------------------
json 1.599M (± 2.5%) i/s (625.34 ns/i) - 7.998M in 5.005110s
oj 2.137M (± 1.5%) i/s (467.99 ns/i) - 10.698M in 5.007806s
rapidjson 1.677M (± 3.5%) i/s (596.31 ns/i) - 8.472M in 5.059515s
Comparison:
json: 1599141.2 i/s
oj: 2136785.3 i/s - 1.34x faster
rapidjson: 1676977.2 i/s - same-ish: difference falls within error
== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 216.464k i/100ms
oj 661.328k i/100ms
rapidjson 324.434k i/100ms
Calculating -------------------------------------
json 2.301M (± 1.7%) i/s (434.57 ns/i) - 11.689M in 5.081278s
oj 7.244M (± 1.2%) i/s (138.05 ns/i) - 36.373M in 5.021985s
rapidjson 3.323M (± 2.9%) i/s (300.96 ns/i) - 16.871M in 5.081696s
Comparison:
json: 2301142.2 i/s
oj: 7243770.3 i/s - 3.15x faster
rapidjson: 3322673.0 i/s - 1.44x faster
```
Now profiles of the `small hash` benchmark show 44% in `generate` and
`45%` in `GeneratorState` allocation.
|
|
* Using the benchmark from https://github.com/flori/json/pull/580
$ ruby benchmarks/bench.rb dump pure
JSON::Pure::Generator
truffleruby 24.0.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
Warming up --------------------------------------
JSON.dump(obj) 116.000 i/100ms
JSON.dump(obj) 235.000 i/100ms
JSON.dump(obj) 317.000 i/100ms
JSON.dump(obj) 372.000 i/100ms
JSON.dump(obj) 374.000 i/100ms
Calculating -------------------------------------
JSON.dump(obj) 3.735k (± 0.9%) i/s (267.76 μs/i) - 18.700k in 5.007526s
JSON.dump(obj) 3.738k (± 0.7%) i/s (267.49 μs/i) - 18.700k in 5.002252s
JSON.dump(obj) 3.743k (± 0.7%) i/s (267.18 μs/i) - 19.074k in 5.096375s
JSON.dump(obj) 3.747k (± 0.5%) i/s (266.87 μs/i) - 19.074k in 5.090463s
JSON.dump(obj) 3.746k (± 0.5%) i/s (266.96 μs/i) - 19.074k in 5.092069s
$ ruby benchmarks/bench.rb dump ext
JSON::Ext::Generator
truffleruby 24.0.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
Warming up --------------------------------------
JSON.dump(obj) 19.000 i/100ms
JSON.dump(obj) 18.000 i/100ms
JSON.dump(obj) 18.000 i/100ms
JSON.dump(obj) 18.000 i/100ms
JSON.dump(obj) 21.000 i/100ms
Calculating -------------------------------------
JSON.dump(obj) 221.260 (±10.8%) i/s (4.52 ms/i) - 1.092k in 5.004381s
JSON.dump(obj) 221.983 (± 8.1%) i/s (4.50 ms/i) - 1.113k in 5.055574s
JSON.dump(obj) 221.446 (± 8.6%) i/s (4.52 ms/i) - 1.113k in 5.073167s
JSON.dump(obj) 226.452 (± 7.9%) i/s (4.42 ms/i) - 1.134k in 5.048568s
JSON.dump(obj) 227.795 (± 8.3%) i/s (4.39 ms/i) - 1.134k in 5.025187s
https://github.com/flori/json/commit/8256455cdc
|
|
https://github.com/flori/json/commit/036944acc6
|
|
https://github.com/flori/json/commit/fff285968d
|
|
https://github.com/flori/json/commit/b507f9e404
|
|
https://github.com/flori/json/commit/202ffe2335
|
|
https://github.com/flori/json/commit/a1af7a308c
|
|
(https://github.com/flori/json/pull/557)
* RDoc for additions
* Update lib/json/add/time.rb
Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
---------
https://github.com/flori/json/commit/3f2efd60f7
Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
|
|
https://github.com/flori/json/commit/41c2712a3b
|
|
https://github.com/flori/json/commit/936f280f9f
|
|
Fix: https://github.com/flori/json/issues/553
We can never add keyword arguments to `dump` otherwise
existing code using unenclosed hash will break.
https://github.com/flori/json/commit/8e0076a3f2
|
|
> https://github.com/flori/json/pull/525
> Rename escape_slash in script_safe and also escape E+2028 and E+2029
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
> https://github.com/flori/json/pull/454
> Remove unnecessary initialization of create_id in JSON.parse()
Co-authored-by: Watson <watson1978@gmail.com>
|
|
It is rather common to directly interpolate JSON string inside
<script> tags in HTML as to provide configuration or parameters to a
script.
However this may lead to XSS vulnerabilities, to prevent that 3
characters need to be escaped:
- `/` (forward slash)
- `U+2028` (LINE SEPARATOR)
- `U+2029` (PARAGRAPH SEPARATOR)
The forward slash need to be escaped to prevent closing the script
tag early, and the other two are valid JSON but invalid Javascript
and can be used to break JS parsing.
Given that the intent of escaping forward slash is the same than escaping
U+2028 and U+2029, I chos to rename and repurpose the existing `escape_slash`
option.
|
|
https://github.com/flori/json/commit/ca546128f2
|
|
https://github.com/flori/json/commit/ec47749b53
|
|
In `JSON#generate` and `JSON#fast_generate`:
- When the given `opts` is a `JSON::State` the variable is set to
`nil`.
- But it will be never used as the next `if` blocks will not be
executed.
- `JSON::State#configure` does the conversion to `Hash`, the
conversions in the `if` block are just duplication.
- `JSON::State.new` does the same thing with `configure` when an
argument is given.
https://github.com/flori/json/commit/5d9ab87f8e
Notes:
Merged: https://github.com/ruby/ruby/pull/8091
|
|
https://github.com/flori/json/commit/3dd36c6077
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/6890
|
|
https://github.com/flori/json/commit/5de358f655
|
|
https://github.com/flori/json/commit/2db5894cfa
|
|
https://github.com/flori/json/commit/da94d9f059
|
|
This change fixes an incorrect `#` position in the API documentation of the `JSON` module.
https://github.com/flori/json/commit/dc4b62424f
|
|
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/3975
|
|
|
|
|
|
|
|
upstream
|
|
Notes:
Merged: https://github.com/ruby/ruby/pull/3753
|
|
https://github.com/flori/json/commit/cb61a00ba8
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
https://github.com/flori/json/commit/6dfa885134
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
* Enhanced RDoc for JSON.dump
https://github.com/flori/json/commit/03f1699ec4
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
https://github.com/flori/json/commit/f8c0fe2408
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
https://github.com/flori/json/commit/a55c91934e
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
https://github.com/flori/json/commit/e4eead665c
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
https://github.com/flori/json/commit/33e64ef255
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
https://github.com/flori/json/commit/20d7be605a
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
issue #386.
https://github.com/flori/json/commit/0be363c99b
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
Squashed commit of the following:
commit 26d181059989279a79c433cedcd893b4f52e42ee
Author: Francois Chagnon <francois.chagnon@jadedpixel.com>
Date: Tue Sep 15 21:17:34 2015 +0000
add config options for escape_slash
commit fa282334051b16df91ca097dd7304b46f3bc7719
Author: Francois Chagnon <francois.chagnon@jadedpixel.com>
Date: Mon Feb 9 21:09:33 2015 +0000
add forward slash to escape character
Notes:
Merged: https://github.com/ruby/ruby/pull/3581
|
|
|
|
https://github.com/flori/json/commit/ee5b6a74e9
|
|
https://github.com/flori/json/commit/ada48f0236
|
|
https://github.com/flori/json/commit/470d909c0d
|
|
https://github.com/flori/json/commit/7bee2c7c13
|