json-as 1.0.0-beta.9 → 1.0.1

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.
Files changed (60) hide show
  1. package/.github/workflows/{nodejs.yml → tests.yml} +1 -1
  2. package/{CHANGELOG → CHANGELOG.md} +45 -0
  3. package/README.md +147 -93
  4. package/assembly/__benches__/abc.bench.ts +21 -0
  5. package/assembly/__benches__/large.bench.ts +174 -0
  6. package/assembly/__benches__/lib/index.ts +26 -0
  7. package/assembly/__benches__/medium.bench.ts +46 -0
  8. package/assembly/__benches__/small.bench.ts +33 -0
  9. package/assembly/__benches__/vec3.bench.ts +72 -0
  10. package/assembly/__tests__/array.spec.ts +42 -0
  11. package/assembly/__tests__/float.spec.ts +3 -3
  12. package/assembly/__tests__/map.spec.ts +7 -0
  13. package/assembly/__tests__/raw.spec.ts +4 -5
  14. package/assembly/__tests__/struct.spec.ts +2 -2
  15. package/assembly/deserialize/simple/arbitrary.ts +8 -4
  16. package/assembly/deserialize/simple/array/arbitrary.ts +6 -6
  17. package/assembly/deserialize/simple/array/array.ts +4 -3
  18. package/assembly/deserialize/simple/array/bool.ts +7 -7
  19. package/assembly/deserialize/simple/array/float.ts +2 -2
  20. package/assembly/deserialize/simple/array/integer.ts +1 -1
  21. package/assembly/deserialize/simple/array/map.ts +1 -1
  22. package/assembly/deserialize/simple/array/string.ts +3 -3
  23. package/assembly/deserialize/simple/array/struct.ts +14 -3
  24. package/assembly/deserialize/simple/array.ts +3 -0
  25. package/assembly/deserialize/simple/map.ts +93 -75
  26. package/assembly/deserialize/simple/object.ts +26 -16
  27. package/assembly/deserialize/simple/struct.ts +31 -19
  28. package/assembly/index.ts +14 -11
  29. package/assembly/serialize/simple/array.ts +1 -0
  30. package/assembly/serialize/simple/bool.ts +1 -0
  31. package/assembly/serialize/simple/date.ts +1 -0
  32. package/assembly/serialize/simple/float.ts +1 -0
  33. package/assembly/serialize/simple/integer.ts +1 -0
  34. package/assembly/serialize/simple/map.ts +1 -0
  35. package/assembly/serialize/simple/object.ts +1 -0
  36. package/assembly/serialize/simple/raw.ts +1 -0
  37. package/assembly/serialize/simple/string.ts +1 -0
  38. package/assembly/test.ts +18 -0
  39. package/bench/abc.bench.ts +20 -0
  40. package/bench/large.bench.ts +126 -0
  41. package/bench/medium.bench.ts +43 -0
  42. package/bench/small.bench.ts +30 -0
  43. package/bench/vec3.bench.ts +26 -0
  44. package/index.ts +1 -1
  45. package/package.json +24 -26
  46. package/run-bench.as.sh +27 -0
  47. package/run-bench.js.sh +12 -0
  48. package/run-tests.sh +14 -2
  49. package/transform/lib/index.js +29 -69
  50. package/transform/lib/index.js.map +1 -1
  51. package/transform/src/index.ts +55 -71
  52. package/.gitmodules +0 -0
  53. package/assembly/__benches__/misc.bench.ts +0 -47
  54. package/assembly/__benches__/schemas.ts +0 -25
  55. package/assembly/__benches__/string.bench.ts +0 -23
  56. package/assembly/__benches__/struct.bench.ts +0 -21
  57. package/assembly/as-bs.d.ts +0 -53
  58. package/bench/schemas.ts +0 -5
  59. package/bench/string.bench.ts +0 -16
  60. /package/bench/{bench.ts → lib/bench.ts} +0 -0
@@ -20,4 +20,4 @@ jobs:
20
20
  run: bun install
21
21
 
22
22
  - name: Run Tests
23
- run: bun run test
23
+ run: bash ./run-tests.sh
@@ -1,5 +1,50 @@
1
1
  # Change Log
2
2
 
3
+ ## 2025-03-10 - 1.0.1
4
+
5
+ - docs: add comprehensive performance metrics
6
+
7
+ ## 2025-03-09 - 1.0.0
8
+
9
+ - fix: relative paths pointing through node_modules would create a second Source
10
+ - feat: move behavior of `--lib` into transform itself
11
+ - fix: object with an object as a value containing a rhs bracket or brace would exit early [3b33e94](https://github.com/JairusSW/json-as/commit/3b33e9414dc04779d22d65272863372fcd7af4a6)
12
+
13
+ ## 2025-03-04 - 1.0.0-beta.17
14
+
15
+ - fix: forgot to build transform
16
+
17
+ ## 2025-03-04 - 1.0.0-beta.16
18
+
19
+ - fix: isPrimitive should only trigger on actual primitives
20
+
21
+ ## 2025-03-04 - 1.0.0-beta.15
22
+
23
+ - fix: deserialize custom should take in string
24
+
25
+ ## 2025-03-04 - 1.0.0-beta.14
26
+
27
+ - fix: reference to nonexistent variable during custom deserialization layer 2
28
+
29
+ ## 2025-03-04 - 1.0.0-beta.13
30
+
31
+ - fix: forgot to actually build the transform
32
+
33
+ ## 2025-03-04 - 1.0.0-beta.12
34
+
35
+ - fix: build transform
36
+
37
+ ## 2025-03-04 - 1.0.0-beta.11
38
+
39
+ - fix: wrongly assumed pointer types within arbitrary deserialization
40
+ - fix: wrong pointer type being passed during map deserialization
41
+
42
+ ## 2025-03-04 - 1.0.0-beta.10
43
+
44
+ - fix: transform not generating the right load operations for keys
45
+ - fix: whitespace not working in objects or struct deserialization
46
+ - fix: JSON.Raw not working when deserializing as Map<string, JSON.Raw>
47
+
3
48
  ## 2025-03-03 - 1.0.0-beta.9
4
49
 
5
50
  - rename: change libs folder to lib
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
7
7
  █████ ███████ ██████ ██ ████ ██ ██ ███████
8
8
  </span>
9
- AssemblyScript - v1.0.0-beta.9
9
+ AssemblyScript - v1.0.1
10
10
  </pre>
11
11
  </h5>
12
12
 
@@ -14,6 +14,18 @@
14
14
 
15
15
  JSON is the de-facto serialization format of modern web applications, but its serialization and deserialization remain a significant performance bottleneck, especially at scale. Traditional parsing approaches are computationally expensive, adding unnecessary overhead to both clients and servers. This library is designed to mitigate this by leveraging SIMD acceleration and highly optimized transformations.
16
16
 
17
+ ## 🔭 What's new
18
+
19
+ 🔹Major performance improvements and addition of SIMD
20
+
21
+ 🔹Near zero-growth allocation design and low overhead
22
+
23
+ 🔹Support for custom serializer and deserializers
24
+
25
+ 🔹Fixes to many, many, bugs and edge cases
26
+
27
+ 🔹Support for dynamic objects, arrays, arbitrary values, and raw types
28
+
17
29
  ## 📚 Contents
18
30
 
19
31
  - [Installation](#-installation)
@@ -31,22 +43,21 @@ JSON is the de-facto serialization format of modern web applications, but its se
31
43
  ## 💾 Installation
32
44
 
33
45
  ```bash
34
- npm install json-as@1.0.0-beta.9
46
+ npm install json-as
35
47
  ```
36
48
 
37
49
  Add the `--transform` to your `asc` command (e.g. in package.json)
38
50
 
39
51
  ```bash
40
- --transform json-as/transform --lib json-as/lib
52
+ --transform json-as/transform
41
53
  ```
42
54
 
43
55
  Alternatively, add it to your `asconfig.json`
44
56
 
45
- ```json
57
+ ```typescript
46
58
  {
47
59
  "options": {
48
- "transform": ["json-as/transform"],
49
- "lib": ["json-as/lib"]
60
+ "transform": ["json-as/transform"]
50
61
  }
51
62
  }
52
63
  ```
@@ -55,7 +66,7 @@ If you'd like to see the code that the transform generates, run with `JSON_DEBUG
55
66
 
56
67
  ## 🪄 Usage
57
68
 
58
- ```js
69
+ ```typescript
59
70
  import { JSON } from "json-as";
60
71
 
61
72
  @json
@@ -82,15 +93,15 @@ class Player {
82
93
  const player: Player = {
83
94
  firstName: "Jairus",
84
95
  lastName: "Tanaka",
85
- lastActive: [2, 13, 2025],
96
+ lastActive: [3, 9, 2025],
86
97
  age: 18,
87
98
  pos: {
88
99
  x: 3.4,
89
100
  y: 1.2,
90
- z: 8.3
101
+ z: 8.3,
91
102
  },
92
- isVerified: true
93
- };
103
+ isVerified: true,
104
+ }
94
105
 
95
106
  const serialized = JSON.stringify<Player>(player);
96
107
  const deserialized = JSON.parse<Player>(serialized);
@@ -109,26 +120,26 @@ This library allows selective omission of fields during serialization using the
109
120
 
110
121
  This decorator excludes a field from serialization entirely.
111
122
 
112
- ```js
123
+ ```typescript
113
124
  @json
114
125
  class Example {
115
126
  name!: string;
116
127
  @omit
117
- secret!: string;
128
+ SSN!: string;
118
129
  }
119
130
 
120
131
  const obj = new Example();
121
- obj.name = "Visible";
122
- obj.secret = "Hidden";
132
+ obj.name = "Jairus";
133
+ obj.SSN = "123-45-6789";
123
134
 
124
- console.log(JSON.stringify(obj)); // { "name": "Visible" }
135
+ console.log(JSON.stringify(obj)); // { "name": "Jairus" }
125
136
  ```
126
137
 
127
138
  **@omitnull**
128
139
 
129
140
  This decorator omits a field only if its value is null.
130
141
 
131
- ```js
142
+ ```typescript
132
143
  @json
133
144
  class Example {
134
145
  name!: string;
@@ -137,30 +148,36 @@ class Example {
137
148
  }
138
149
 
139
150
  const obj = new Example();
140
- obj.name = "Present";
151
+ obj.name = "Jairus";
141
152
  obj.optionalField = null;
142
153
 
143
- console.log(JSON.stringify(obj)); // { "name": "Present" }
154
+ console.log(JSON.stringify(obj)); // { "name": "Jairus" }
155
+ ```
144
156
 
145
- @omitif((self: this) => condition)
157
+ **@omitif((self: this) => condition)**
146
158
 
147
159
  This decorator omits a field based on a custom predicate function.
148
160
 
161
+ ```typescript
149
162
  @json
150
163
  class Example {
151
164
  name!: string;
152
- @omitif((self: Example) => self.age < 18)
165
+ @omitif((self: Example) => self.age <= 18)
153
166
  age!: number;
154
167
  }
155
168
 
156
169
  const obj = new Example();
157
- obj.name = "John";
158
- obj.age = 16;
170
+ obj.name = "Jairus";
171
+ obj.age = 18;
172
+
173
+ console.log(JSON.stringify(obj)); // { "name": "Jairus" }
174
+
175
+ obj.age = 99;
159
176
 
160
- console.log(JSON.stringify(obj)); // { "name": "John" }
177
+ console.log(JSON.stringify(obj)); // { "name": "Jairus", "age": 99 }
161
178
  ```
162
179
 
163
- If age were 18 or higher, it would be included in the serialization.
180
+ If age were higher than 18, it would be included in the serialization.
164
181
 
165
182
  ### 🗳️ Using nullable primitives
166
183
 
@@ -168,7 +185,7 @@ AssemblyScript doesn't support using nullable primitive types, so instead, json-
168
185
 
169
186
  For example, this schema won't compile in AssemblyScript:
170
187
 
171
- ```js
188
+ ```typescript
172
189
  @json
173
190
  class Person {
174
191
  name!: string;
@@ -178,7 +195,7 @@ class Person {
178
195
 
179
196
  Instead, use `JSON.Box` to allow nullable primitives:
180
197
 
181
- ```js
198
+ ```typescript
182
199
  @json
183
200
  class Person {
184
201
  name: string;
@@ -188,11 +205,11 @@ class Person {
188
205
  }
189
206
  }
190
207
 
191
- const person = new Person("Bob");
192
- console.log(JSON.stringify(person)); // {"name":"Bob","age":null}
208
+ const person = new Person("Jairus");
209
+ console.log(JSON.stringify(person)); // {"name":"Jairus","age":null}
193
210
 
194
211
  person.age = new JSON.Box<i32>(18); // Set age to 18
195
- console.log(JSON.stringify(person)); // {"name":"Bob","age":18}
212
+ console.log(JSON.stringify(person)); // {"name":"Jairus","age":18}
196
213
  ```
197
214
 
198
215
  ### 📤 Working with unknown or dynamic data
@@ -205,31 +222,31 @@ Here's a few examples:
205
222
 
206
223
  **Working with multi-type arrays**
207
224
 
208
- When dealing with arrays that have multiple types within them, eg. `["string",true,null,["array"]]`, use `JSON.Value[]`
225
+ When dealing with arrays that have multiple types within them, eg. `["string",true,["array"]]`, use `JSON.Value[]`
209
226
 
210
- ```js
211
- const a1 = JSON.parse<JSON.Value[]>('["string",true,null,["array"]]');
227
+ ```typescript
228
+ const a = JSON.parse<JSON.Value[]>('["string",true,["array"]]');
212
229
  console.log(JSON.stringify(a[0])); // "string"
213
230
  console.log(JSON.stringify(a[1])); // true
214
- console.log(JSON.stringify(a[2])); // null
215
- console.log(JSON.stringify(a[3])); // ["array"]
231
+ console.log(JSON.stringify(a[2])); // ["array"]
216
232
  ```
217
233
 
218
234
  **Working with unknown objects**
219
235
 
220
236
  When dealing with an object with an unknown structure, use the `JSON.Obj` type
221
237
 
222
- ```js
223
- const o1 = JSON.parse<JSON.Obj>('{"a":3.14,"b":true,"c":[1,2,3],"d":{"x":1,"y":2,"z":3}}');
238
+ ```typescript
239
+ const obj = JSON.parse<JSON.Obj>('{"a":3.14,"b":true,"c":[1,2,3],"d":{"x":1,"y":2,"z":3}}');
224
240
 
225
- console.log(o1.keys().join(" ")); // a b c d
226
- console.log(
227
- o1.values()
228
- .map<string>((v) => JSON.stringify(v))
229
- .join(" ")
241
+ console.log("Keys: " + obj.keys().join(" ")); // a b c d
242
+ console.log("Values: " +
243
+ obj
244
+ .values()
245
+ .map<string>((v) => JSON.stringify(v))
246
+ .join(" "),
230
247
  ); // 3.14 true [1,2,3] {"x":1,"y":2,"z":3}
231
248
 
232
- const y = o1.get("d").get<JSON.Obj>().get<i32>();
249
+ const y = obj.get("d")!.get<JSON.Obj>().get("y")!;
233
250
  console.log('o1["d"]["y"] = ' + y.toString()); // o1["d"]["y"] = 2
234
251
  ```
235
252
 
@@ -239,7 +256,7 @@ More often, objects will be completely statically typed except for one or two va
239
256
 
240
257
  In such cases, `JSON.Value` can be used to handle fields that may hold different types at runtime.
241
258
 
242
- ```js
259
+ ```typescript
243
260
  @json
244
261
  class DynamicObj {
245
262
  id: i32 = 0;
@@ -267,24 +284,22 @@ Sometimes its necessary to simply copy a string instead of serializing it.
267
284
 
268
285
  For example, the following data would typically be serialized as:
269
286
 
270
- ```js
271
- const m1 = new Map<string, string>();
272
- m1.set('pos', '{"x":1.0,"y":2.0,"z":3.0}');
287
+ ```typescript
288
+ const map = new Map<string, string>();
289
+ map.set("pos", '{"x":1.0,"y":2.0,"z":3.0}');
273
290
 
274
- const a1 = JSON.stringify(m1);
275
- console.log("a1: " + a1);
291
+ console.log(JSON.stringify(map));
276
292
  // {"pos":"{\"x\":1.0,\"y\":2.0,\"z\":3.0}"}
277
293
  // pos's value (Vec3) is contained within a string... ideally, it should be left alone
278
294
  ```
279
295
 
280
296
  If, instead, one wanted to insert Raw JSON into an existing schema/data structure, they could make use of the JSON.Raw type to do so:
281
297
 
282
- ```js
283
- const m1 = new Map<string, JSON.Raw>();
284
- m1.set('pos', new JSON.Raw('{"x":1.0,"y":2.0,"z":3.0}'));
298
+ ```typescript
299
+ const map = new Map<string, JSON.Raw>();
300
+ map.set("pos", new JSON.Raw('{"x":1.0,"y":2.0,"z":3.0}'));
285
301
 
286
- const a1 = JSON.stringify(m1);
287
- console.log("a1: " + a1);
302
+ console.log(JSON.stringify(map));
288
303
  // {"pos":{"x":1.0,"y":2.0,"z":3.0}}
289
304
  // Now its properly formatted JSON where pos's value is of type Vec3 not string!
290
305
  ```
@@ -295,7 +310,9 @@ This library supports custom serialization and deserialization methods, which ca
295
310
 
296
311
  Here's an example of creating a custom data type called `Point` which serializes to `(x,y)`
297
312
 
298
- ```js
313
+ ```typescript
314
+ import { bytes } from "json-as/assembly/util";
315
+
299
316
  @json
300
317
  class Point {
301
318
  x: f64 = 0.0;
@@ -319,12 +336,17 @@ class Point {
319
336
  const x = data.slice(1, c);
320
337
  const y = data.slice(c + 1, data.length - 1);
321
338
 
322
- return new Point(
323
- f64.parse(x),
324
- f64.parse(y)
325
- );
339
+ return new Point(f64.parse(x), f64.parse(y));
326
340
  }
327
341
  }
342
+
343
+ const obj = new Point(3.5, -9.2);
344
+
345
+ const serialized = JSON.stringify<Point>(obj);
346
+ const deserialized = JSON.parse<Point>(serialized);
347
+
348
+ console.log("Serialized " + serialized);
349
+ console.log("Deserialized " + JSON.stringify(deserialized));
328
350
  ```
329
351
 
330
352
  The serializer function converts a `Point` instance into a string format `(x,y)`.
@@ -333,7 +355,7 @@ The deserializer function parses the string `(x,y)` back into a `Point` instance
333
355
 
334
356
  These functions are then wrapped before being consumed by the json-as library:
335
357
 
336
- ```js
358
+ ```typescript
337
359
  @inline __SERIALIZE_CUSTOM(ptr: usize): void {
338
360
  const data = this.serializer(changetype<Point>(ptr));
339
361
  const dataSize = data.length << 1;
@@ -350,47 +372,79 @@ This allows custom serialization while maintaining a generic interface for the l
350
372
 
351
373
  ## ⚡ Performance
352
374
 
353
- The `json-as` library has been optimized to achieve near-gigabyte-per-second JSON processing speeds through SIMD acceleration and highly efficient transformations. Below are some key performance benchmarks to give you an idea of how it performs.
375
+ The `json-as` library has been optimized to achieve near-gigabyte-per-second JSON processing speeds through SIMD acceleration and highly efficient transformations. Below are detailed statistics comparing performance metrics such as build time, operations-per-second, and throughput.
376
+
377
+ ### 🔍 Comparison to JavaScript
378
+
379
+ These benchmarks compare this library to JavaScript's native `JSON.stringify` and `JSON.parse` functions.
380
+
381
+ **Table 1** - _AssemblyScript (LLVM)_
382
+
383
+ | Test Case | Size | Serialization (ops/s) | Deserialization (ops/s) | Serialization (MB/s) | Deserialization (MB/s) |
384
+ | --------------- | ---------- | --------------------- | ----------------------- | -------------------- | ---------------------- |
385
+ | Vector3 Object | 38 bytes | 35,714,285 ops/s | 35,435,552 ops/s | 1,357 MB/s | 1,348 MB/s |
386
+ | Alphabet String | 104 bytes | 13,617,021 ops/s | 18,390,804 ops/s | 1,416 MB/s | 1,986 MB/s |
387
+ | Small Object | 88 bytes | 24,242,424 ops/s | 12,307,692 ops/s | 2,133 MB/s | 1,083 MB/s |
388
+ | Medium Object | 494 bytes | 4,060,913 ops/s | 1,396,160 ops/s | 2,006 MB/s | 689.7 MB/s |
389
+ | Large Object | 3374 bytes | 614,754 ops/s | 132,802 ops/s | 2,074 MB/s | 448.0 MB/s |
390
+
391
+ **Table 2** - _JavaScript (V8)_
392
+
393
+ | Test Case | Size | Serialization (ops/s) | Deserialization (ops/s) | Serialization (MB/s) | Deserialization (MB/s) |
394
+ | --------------- | ---------- | --------------------- | ----------------------- | -------------------- | ---------------------- |
395
+ | Vector3 Object | 38 bytes | 8,791,209 ops/s | 5,369,12 ops/s | 357.4 MB/s | 204.3 MB/s |
396
+ | Alphabet String | 104 bytes | 13,793,103 ops/s | 14,746,544 ops/s | 1,416 MB/s | 1,592 MB/s |
397
+ | Small Object | 88 bytes | 8,376,963 ops/s | 4,968,944 ops/s | 737.1 MB/s | 437.2 MB/s |
398
+ | Medium Object | 494 bytes | 2,395,210 ops/s | 1,381,693 ops/s | 1,183 MB/s | 682.5 MB/s |
399
+ | Large Object | 3374 bytes | 222,222 ops/s | 117,233 ops/s | 749.7 MB/s | 395.5 MB/s |
400
+
401
+ **📌 Insights**
402
+
403
+ - JSON-AS consistently outperforms JavaScript's native implementation.
404
+
405
+ - **Serialization Speed:**
406
+ - JSON-AS achieves speeds up to `2,133 MB/s`, significantly faster than JavaScript's peak of `1,416 MB/s`.
407
+ - Large objects see the biggest improvement, with JSON-AS at `2,074 MB/s` vs. JavaScript’s `749.7 MB/s`.
408
+
409
+ - **Deserialization Speed:**
410
+ - JSON-AS reaches `1,986 MB/s`, while JavaScript caps at `1,592 MB/s`.
411
+ - Small and medium objects see the most significant performance boost overall.
354
412
 
355
- ### Raw Performance
413
+ ### 📈 Comparison to v0.9.x version
356
414
 
357
- Simple
415
+ **Table 1** - _v1.0.0_
358
416
 
359
- | Test Case | Serialization (ops/s) | Deserialization (ops/s) | Serialization (MB/s) | Deserialization (MB/s) |
360
- | ------------------ | --------------------- | ----------------------- | -------------------- | ---------------------- |
361
- | Vector3 Object | 32,642,320 ops/s | 9,736,272 ops/s | 1,240 MB/s | 369 MB/s |
362
- | Alphabet String | 4,928,856 ops/s | 7,567,360 ops/s | 975 MB/s | 1,498 MB/s |
363
- | Small JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
364
- | Medium JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
365
- | Large JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
417
+ | Test Case | Size | Serialization (ops/s) | Deserialization (ops/s) | Serialization (MB/s) | Deserialization (MB/s) |
418
+ | --------------- | ---------- | --------------------- | ----------------------- | -------------------- | ---------------------- |
419
+ | Vector3 Object | 38 bytes | 35,714,285 ops/s | 35,435,552 ops/s | 1,357 MB/s | 1,348 MB/s |
420
+ | Alphabet String | 104 bytes | 13,617,021 ops/s | 18,390,804 ops/s | 1,416 MB/s | 1,986 MB/s |
421
+ | Small Object | 88 bytes | 24,242,424 ops/s | 12,307,692 ops/s | 2,133 MB/s | 1,083 MB/s |
422
+ | Medium Object | 494 bytes | 4,060,913 ops/s | 1,396,160 ops/s | 2,006 MB/s | 689.7 MB/s |
423
+ | Large Object | 3374 bytes | 614,754 ops/s | 132,802 ops/s | 2,074 MB/s | 448.0 MB/s |
366
424
 
367
- SIMD
425
+ **Table 2** - _v0.9.29_
368
426
 
369
- | Test Case | Serialization (ops/s) | Deserialization (ops/s) | Serialization (MB/s) | Deserialization (MB/s) |
370
- | ------------------ | --------------------- | ----------------------- | -------------------- | ---------------------- |
371
- | Vector3 Object | 32,642,320 ops/s | 9,736,272 ops/s | 1,240 MB/s | 369 MB/s |
372
- | Alphabet String | 20,368,584 ops/s | 28,467,424 ops/s | 3,910 MB/s | 5,636 MB/s |
373
- | Small JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
374
- | Medium JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
375
- | Large JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
427
+ | Test Case | Size | Serialization (ops/s) | Deserialization (ops/s) | Serialization (MB/s) | Deserialization (MB/s) |
428
+ | --------------- | ---------- | --------------------- | ----------------------- | -------------------- | ---------------------- |
429
+ | Vector3 Object | 38 bytes | 6,896,551 ops/s | 10,958,904 ops/s | 262.1 MB/s | 416.4 MB/s |
430
+ | Alphabet String | 104 bytes | 5,128,205 ops/s | 8,695,652 ops/s | 533.3 MB/s | 939.1 MB/s |
431
+ | Small Object | 88 bytes | 4,953,560 ops/s | 3,678,160 ops/s | 435.9 MB/s | 323.7 MB/s |
432
+ | Medium Object | 494 bytes | 522,193 ops/s | 508,582 ops/s | 258.0 MB/s | 251.2 MB/s |
433
+ | Large Object | 3374 bytes | 51,229 ops/s | 65,585 ops/s | 172.8 MB/s | 221.3 MB/s |
376
434
 
377
- JavaScript
435
+ **📌 Insights:**
378
436
 
379
- | Test Case | Serialization (ops/s) | Deserialization (ops/s) | Serialization (MB/s) | Deserialization (MB/s) |
380
- | ------------------ | --------------------- | ----------------------- | -------------------- | ---------------------- |
381
- | Vector3 Object | 2,548,013 ops/s | 1,942,440 ops/s | 97 MB/s | 73 MB/s |
382
- | Alphabet String | 3,221,556 ops/s | 2,716,617 ops/s | 624 MB/s | 537 MB/s |
383
- | Small JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
384
- | Medium JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
385
- | Large JSON Object | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
437
+ - Massive performance improvements in JSON-AS `v1.0.0`:
438
+ - Serialization is **2-12x faster** (e.g., Large Object: `2,074 MB/s` vs. `172.8 MB/s`).
439
+ - Deserialization is **2-3x faster** (e.g., Large Object: `1,348 MB/s` vs. `221.3 MB/s`).
440
+ - Vector3 Object serialization improved from `416 MB/s` to `1,357 MB/s`--a **3x benefit** through new code generation techniques.
386
441
 
387
- ### Real-World Usage
442
+ ## 🔭 What's Next
388
443
 
389
- | Scenario | JSON Size (kb) | Serialization Time (ops/s) | Deserialization Time (ops/s) | Throughput (GB/s) |
390
- | ---------------- | -------------- | -------------------------- | ---------------------------- | ----------------- |
391
- | Web API Response | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
392
- | Database Entry | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
393
- | File Parsing | [Fill Value] | [Fill Value] | [Fill Value] | [Fill Value] |
444
+ - Theorize plans to keep key-order in generated schemas
445
+ - Generate optimized deserialization methods
446
+ - Inline specific hot code paths
447
+ - Implement error handling implementation
394
448
 
395
449
  ## 📃 License
396
450
 
@@ -403,4 +457,4 @@ Please send all issues to [GitHub Issues](https://github.com/JairusSW/json-as/is
403
457
  - **Email:** Send me inquiries, questions, or requests at [me@jairus.dev](mailto:me@jairus.dev)
404
458
  - **GitHub:** Visit the official GitHub repository [Here](https://github.com/JairusSW/json-as)
405
459
  - **Website:** Visit my official website at [jairus.dev](https://jairus.dev/)
406
- - **Discord:** Contact me at [My Discord](https://discord.com/users/600700584038760448) or on the [AssemblyScript Discord Server](https://discord.gg/assemblyscript/)
460
+ - **Discord:** Contact me at [My Discord](https://discord.com/users/600700584038760448) or on the [AssemblyScript Discord Server](https://discord.gg/assemblyscript/)
@@ -0,0 +1,21 @@
1
+ import { JSON } from "..";
2
+ import { bench } from "../custom/bench";
3
+
4
+ const v1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
5
+ const v2 = '"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"';
6
+
7
+ bench(
8
+ "Serialize Alphabet",
9
+ () => {
10
+ JSON.stringify(v1);
11
+ },
12
+ 1_000_00,
13
+ );
14
+
15
+ bench(
16
+ "Deserialize Alphabet",
17
+ () => {
18
+ JSON.parse<string>(v2);
19
+ },
20
+ 1_000_00,
21
+ );