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 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 minimal runtime which doesn't call the Garbage Collector, so you may expect a 10% to 40% decrease from low to high throughput.
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 (TinyBench/NodeJS 19)
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
- │ Task Name │ ops / sec │ Average Time(ns) │ Margin │
82
- ├───────────────────────────┼─────────────┼────────────────────┼──────────┤
83
- │ 'Stringify Object (Vec3)' │ '817,816' │ 1222.76 │ '±3.55%' │
84
- 'Parse Object (Vec3)' │ '726,115' │ 1377.19 │ '±3.21%' │
85
- 'Stringify Number Array' '1,104,036' │ 905.77 │ '±6.48%' │
86
- 'Parse Number Array' '1,114,053' 897.62 │ '±2.58%' │
87
- 'Stringify String' '1,565,716' 638.69 │ '±2.04%' │
88
- 'Parse String' │ '69,568' 14374.22 │ '±2.55%' │
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
- │ Task Name │ ops / sec │ Average Time(ns) │ Diff │
96
- ├───────────────────────────┼─────────────┼────────────────────┼──────────┤
97
- │ 'Stringify Object (Vec3)' │ '2,091,000' │ 417.22 │ -805ns │
98
- 'Parse Object (Vec3)' '1,780,000' 539.02 │ -838ns |
99
- 'Stringify Number Array' '1,920,000' │ 445.43 │ -460ns │
100
- 'Parse Number Array' '1,660,000' │ 597.17 │ -300ns
101
- 'Stringify String' '1,280,000' │ 736.27 │ +97ns
102
- 'Parse String' '4,230,000' 239.21 │ -14135ns │
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
@@ -0,0 +1,15 @@
1
+ {
2
+ "targets": {
3
+ "test": {
4
+ "outFile": "build/test.wasm",
5
+ "sourceMap": false,
6
+ "optimizeLevel": 0,
7
+ "shrinkLevel": 0,
8
+ "converge": false,
9
+ "noAssert": false
10
+ }
11
+ },
12
+ "options": {
13
+ "transform": ["./transform"]
14
+ }
15
+ }
@@ -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>(atoi_fast<i32>("12345"));
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
- //bench("Parse Object (Vec3)", () => {
38
- // blackbox<Vec3>(vec.__JSON_Deserialize('{"x":0,"y":0,"z":0}', vec));
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", () => {
@@ -1,29 +1,55 @@
1
1
  // Characters
2
- export const commaCode = ",".charCodeAt(0);
3
- export const quoteCode = '"'.charCodeAt(0);
4
- export const backSlashCode = "\\".charCodeAt(0);
5
- export const forwardSlashCode = "/".charCodeAt(0);
6
- export const leftBraceCode = "{".charCodeAt(0);
7
- export const rightBraceCode = "}".charCodeAt(0);
8
- export const leftBracketCode = "[".charCodeAt(0);
9
- export const rightBracketCode = "]".charCodeAt(0);
10
- export const colonCode = ":".charCodeAt(0);
11
- export const tCode = "t".charCodeAt(0);
12
- export const rCode = "r".charCodeAt(0);
13
- export const uCode = "u".charCodeAt(0);
14
- export const eCode = "e".charCodeAt(0);
15
- export const fCode = "f".charCodeAt(0);
16
- export const aCode = "a".charCodeAt(0);
17
- export const lCode = "l".charCodeAt(0);
18
- export const sCode = "s".charCodeAt(0);
19
- export const nCode = "n".charCodeAt(0);
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
- export const trueWord = "true";
22
- export const falseWord = "false";
23
- export const nullWord = "null";
24
- export const leftBracketWord = "[";
25
- export const emptyArrayWord = "[]";
26
- export const commaWord = ",";
27
- export const rightBracketWord = "]";
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
- export const newLineCode = "\n".charCodeAt(0);
54
+ // @ts-ignore: Decorator is valid here
55
+ @inline export const newLineCode = 10;