json-as 0.5.54 → 0.5.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +41 -23
- package/asconfig.json +15 -0
- package/assembly/__benches__/as-json.ts +10 -10
- package/assembly/__tests__/as-json.spec.ts +1 -1
- package/assembly/src/chars.ts +52 -26
- package/assembly/src/json.ts +108 -151
- package/assembly/src/util.ts +42 -31
- package/assembly/test.ts +80 -5
- package/bench/bench-node.js +17 -0
- package/bench/benchmark.ts +60 -0
- package/bench/tsconfig.json +99 -0
- package/package.json +13 -6
- package/transform/lib/index.js +26 -11
- package/transform/package.json +1 -1
- package/transform/src/index.ts +44 -22
- package/bench-results/INTEGER-PARSING.md +0 -52
package/LICENSE
CHANGED
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -71,36 +71,54 @@ const parsed = JSON.parse<Player>(stringified);
|
|
|
71
71
|
## Performance
|
|
72
72
|
|
|
73
73
|
Here are some benchmarks I took with `tinybench` (JavaScript) and `astral` (AssemblyScript).
|
|
74
|
-
I took the benchmarks using the
|
|
74
|
+
I took the benchmarks using the stub runtime which doesn't call the Garbage Collector, so you may expect a 10% to 40% decrease from low to high throughput.
|
|
75
75
|
|
|
76
76
|
Tests are run on Ubuntu/WSL2 with a AMD Ryzen 9 CPU
|
|
77
77
|
|
|
78
|
-
JavaScript Results
|
|
78
|
+
JavaScript Results
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
NodeJS v20.5.1 - TinyBench v2.5.0 (V8)
|
|
82
|
+
┌───────────────────────────┬───────────────┐
|
|
83
|
+
│ Task Name │ ops / sec │
|
|
84
|
+
├───────────────────────────┼───────────────┤
|
|
85
|
+
│ 'Stringify Object (Vec3)' │ '1,191,221' │
|
|
86
|
+
│ 'Parse Object (Vec3)' │ '897,759' │
|
|
87
|
+
│ 'Stringify Number Array' │ '1,552,255' │
|
|
88
|
+
│ 'Parse Number Array' │ '1,225,325' │
|
|
89
|
+
│ 'Stringify String' │ '1,761,011' │
|
|
90
|
+
│ 'Parse String' │ '80,845' │
|
|
91
|
+
└───────────────────────────┴───────────────┘
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
AssemblyScript Results
|
|
95
|
+
|
|
79
96
|
```
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
│
|
|
85
|
-
│
|
|
86
|
-
│
|
|
87
|
-
│
|
|
88
|
-
│
|
|
89
|
-
|
|
97
|
+
WAVM v0.0.0-prerelease - as-bench v0.0.0-alpha (LLVM)
|
|
98
|
+
┌───────────────────────────┬───────────────┐
|
|
99
|
+
│ Task Name │ ops / sec │
|
|
100
|
+
├───────────────────────────┼───────────────┤
|
|
101
|
+
│ 'Stringify Object (Vec3)' │ '6,270,322' │
|
|
102
|
+
│ 'Parse Object (Vec3)' │ '8,000,195' |
|
|
103
|
+
│ 'Stringify Number Array' │ '6,664,937' │
|
|
104
|
+
│ 'Parse Number Array' │ '6,557,357' │
|
|
105
|
+
│ 'Stringify String' │ '6,946,947' │
|
|
106
|
+
│ 'Parse String' │ '10,952,502' │
|
|
107
|
+
└───────────────────────────┴───────────────┘
|
|
90
108
|
```
|
|
91
109
|
|
|
92
|
-
AssemblyScript Results (Runtime Minimal)
|
|
93
110
|
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
│
|
|
99
|
-
│
|
|
100
|
-
│
|
|
101
|
-
│
|
|
102
|
-
│
|
|
103
|
-
|
|
111
|
+
Wasmtime v11.0.1 - as-bench v0.0.0-alpha (Cranelift)
|
|
112
|
+
┌───────────────────────────┬───────────────┐
|
|
113
|
+
│ Task Name │ ops / sec │
|
|
114
|
+
├───────────────────────────┼───────────────┤
|
|
115
|
+
│ 'Stringify Object (Vec3)' │ '2,038,684' │
|
|
116
|
+
│ 'Parse Object (Vec3)' │ '4,623,337' |
|
|
117
|
+
│ 'Stringify Number Array' │ '2,500,947' │
|
|
118
|
+
│ 'Parse Number Array' │ '2,959,180' │
|
|
119
|
+
│ 'Stringify String' │ '3,236,896' │
|
|
120
|
+
│ 'Parse String' │ '5,634,594' │
|
|
121
|
+
└───────────────────────────┴───────────────┘
|
|
104
122
|
```
|
|
105
123
|
|
|
106
124
|
## Issues
|
package/asconfig.json
ADDED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSON } from "..";
|
|
2
|
-
import { snip_fast } from "../src/util";
|
|
2
|
+
import { __atoi_fast, snip_fast } from "../src/util";
|
|
3
3
|
@json
|
|
4
4
|
class Vec3 {
|
|
5
5
|
x: i32;
|
|
@@ -12,13 +12,13 @@ const vec: Vec3 = {
|
|
|
12
12
|
y: 1,
|
|
13
13
|
z: 8,
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
/*
|
|
16
16
|
bench("Parse Number SNIP", () => {
|
|
17
17
|
blackbox<i32>(snip_fast<i32>("12345"));
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
bench("Parse Number ATOI", () => {
|
|
21
|
-
blackbox<i32>(
|
|
21
|
+
blackbox<i32>(__atoi_fast<i32>("12345"));
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
bench("Parse Number STDLIB", () => {
|
|
@@ -28,16 +28,16 @@ bench("Parse Number STDLIB", () => {
|
|
|
28
28
|
bench("Parse Number OLD", () => {
|
|
29
29
|
blackbox<i32>(parseSciInteger<i32>("12345"));
|
|
30
30
|
});
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
bench("Stringify Object (Vec3)", () => {
|
|
33
33
|
blackbox<string>(vec.__JSON_Serialize());
|
|
34
|
-
})
|
|
34
|
+
});*/
|
|
35
35
|
|
|
36
36
|
// TODO: Make this allocate without crashing
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
bench("Parse Object (Vec3)", () => {
|
|
38
|
+
blackbox<Vec3>(JSON.parse<Vec3>('{"x":0,"y":0,"z":0}'));
|
|
39
|
+
});
|
|
40
|
+
/*
|
|
41
41
|
bench("Stringify Number Array", () => {
|
|
42
42
|
blackbox(JSON.stringify<i32[]>([1, 2, 3]));
|
|
43
43
|
});
|
|
@@ -89,7 +89,7 @@ describe("Ser/de Array", () => {
|
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
it("should ser/de string arrays", () => {
|
|
92
|
-
canSerde<string[]>(['string \"with random spa\nces and \nnewlines\n\n\n']);
|
|
92
|
+
canSerde<string[]>(['string \"with random spa\nces and \nnewlines\n\n\n'], '["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]');
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
it("should ser/de nested integer arrays", () => {
|
package/assembly/src/chars.ts
CHANGED
|
@@ -1,29 +1,55 @@
|
|
|
1
1
|
// Characters
|
|
2
|
-
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
export const
|
|
14
|
-
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
export const
|
|
2
|
+
// @ts-ignore = Decorator is valid here
|
|
3
|
+
@inline export const commaCode = 44;
|
|
4
|
+
// @ts-ignore = Decorator is valid here
|
|
5
|
+
@inline export const quoteCode = 34;
|
|
6
|
+
// @ts-ignore = Decorator is valid here
|
|
7
|
+
@inline export const backSlashCode = 92;
|
|
8
|
+
// @ts-ignore: Decorator is valid here
|
|
9
|
+
@inline export const forwardSlashCode = 47;
|
|
10
|
+
// @ts-ignore: Decorator is valid here
|
|
11
|
+
@inline export const leftBraceCode = 123;
|
|
12
|
+
// @ts-ignore: Decorator is valid here
|
|
13
|
+
@inline export const rightBraceCode = 125;
|
|
14
|
+
// @ts-ignore: Decorator is valid here
|
|
15
|
+
@inline export const leftBracketCode = 91;
|
|
16
|
+
// @ts-ignore: Decorator is valid here
|
|
17
|
+
@inline export const rightBracketCode = 93;
|
|
18
|
+
// @ts-ignore: Decorator is valid here
|
|
19
|
+
@inline export const colonCode = 58;
|
|
20
|
+
// @ts-ignore: Decorator is valid here
|
|
21
|
+
@inline export const tCode = 116;
|
|
22
|
+
// @ts-ignore: Decorator is valid here
|
|
23
|
+
@inline export const rCode = 114;
|
|
24
|
+
// @ts-ignore: Decorator is valid here
|
|
25
|
+
@inline export const uCode = 117;
|
|
26
|
+
// @ts-ignore: Decorator is valid here
|
|
27
|
+
@inline export const eCode = 101;
|
|
28
|
+
// @ts-ignore: Decorator is valid here
|
|
29
|
+
@inline export const fCode = 102;
|
|
30
|
+
// @ts-ignore: Decorator is valid here
|
|
31
|
+
@inline export const aCode = 97;
|
|
32
|
+
// @ts-ignore: Decorator is valid here
|
|
33
|
+
@inline export const lCode = 108;
|
|
34
|
+
// @ts-ignore: Decorator is valid here
|
|
35
|
+
@inline export const sCode = 115;
|
|
36
|
+
// @ts-ignore = Decorator is valid here
|
|
37
|
+
@inline export const nCode = 110;
|
|
20
38
|
// Strings
|
|
21
|
-
|
|
22
|
-
export const
|
|
23
|
-
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
export const
|
|
27
|
-
|
|
39
|
+
// @ts-ignore: Decorator is valid here
|
|
40
|
+
@inline export const trueWord = "true";
|
|
41
|
+
// @ts-ignore: Decorator is valid here
|
|
42
|
+
@inline export const falseWord = "false";
|
|
43
|
+
// @ts-ignore: Decorator is valid here
|
|
44
|
+
@inline export const nullWord = "null";
|
|
45
|
+
// @ts-ignore: Decorator is valid here
|
|
46
|
+
@inline export const leftBracketWord = "[";
|
|
47
|
+
// @ts-ignore: Decorator is valid here
|
|
48
|
+
@inline export const emptyArrayWord = "[]";
|
|
49
|
+
// @ts-ignore: Decorator is valid here
|
|
50
|
+
@inline export const commaWord = ",";
|
|
51
|
+
// @ts-ignore: Decorator is valid here
|
|
52
|
+
@inline export const rightBracketWord = "]";
|
|
28
53
|
// Escape Codes
|
|
29
|
-
|
|
54
|
+
// @ts-ignore: Decorator is valid here
|
|
55
|
+
@inline export const newLineCode = 10;
|