Commit 9a00965
Use a table to check for escaping needs
This performs noticeably better than the boolean logic.
Before:
```
== Encoding twitter.json (466906 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 189.000 i/100ms
oj 228.000 i/100ms
rapidjson 108.000 i/100ms
Calculating -------------------------------------
json 1.903k (± 1.2%) i/s (525.55 μs/i) - 9.639k in 5.066521s
oj 2.306k (± 1.3%) i/s (433.71 μs/i) - 11.628k in 5.044096s
rapidjson 1.069k (± 2.4%) i/s (935.38 μs/i) - 5.400k in 5.053794s
Comparison:
json: 1902.8 i/s
oj: 2305.7 i/s - 1.21x faster
rapidjson: 1069.1 i/s - 1.78x slower
```
After:
```
== Encoding twitter.json (466906 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json 224.000 i/100ms
oj 230.000 i/100ms
rapidjson 107.000 i/100ms
Calculating -------------------------------------
json 2.254k (± 1.6%) i/s (443.69 μs/i) - 11.424k in 5.069999s
oj 2.318k (± 1.4%) i/s (431.32 μs/i) - 11.730k in 5.060421s
rapidjson 1.081k (± 1.9%) i/s (925.05 μs/i) - 5.457k in 5.049738s
Comparison:
json: 2253.8 i/s
oj: 2318.5 i/s - same-ish: difference falls within error
rapidjson: 1081.0 i/s - 2.08x slower
```
The escape table is taken directly from Mame's PR.
Co-Authored-By: Yusuke Endoh <[email protected]>1 parent 2aefa41 commit 9a00965
1 file changed
+25
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
121 | 143 | | |
122 | 144 | | |
123 | 145 | | |
| |||
129 | 151 | | |
130 | 152 | | |
131 | 153 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | 154 | | |
142 | | - | |
| 155 | + | |
143 | 156 | | |
144 | 157 | | |
145 | 158 | | |
| |||
717 | 730 | | |
718 | 731 | | |
719 | 732 | | |
720 | | - | |
| 733 | + | |
721 | 734 | | |
722 | 735 | | |
723 | 736 | | |
| |||
0 commit comments