Skip to content

Commit

Permalink
fix: #104
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jan 14, 2025
1 parent 32fcf18 commit a61c068
Show file tree
Hide file tree
Showing 104 changed files with 3,440 additions and 8,032 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ jobs:
- name: Install Dependencies
run: bun install

- name: Build Tests
run: bun run pretest

- name: Run Tests
run: bun run test
21 changes: 12 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
node_modules
*.lock
pnpm-lock.yaml
package-lock.json
.vscode
logs
as-tral
*.lockb
.vscode/
# Package Manager
node_modules
*.lock
pnpm-lock.yaml
package-lock.json
*.lockb

# IDE Files
.vscode/

# Build Artifacts
as-tral/
build/
5 changes: 1 addition & 4 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"pluginSearchDirs": ["node_modules"],
"plugins": ["assemblyscript-prettier"],
"singleQuote": false,
"printWidth": 65536,
"tabWidth": 2
"printWidth": 65536
}
52 changes: 9 additions & 43 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
v0.8.2 - Properties starting with `static` or `private` would be ignored
v0.8.3 - Dirty fix to issue #68. Add __JSON_Stringify callable to global scope.
v0.8.4 - Fix #71. Classes with the extending class overriding a property cause the property to be serialized twice.
v0.8.5 - Fix #73. Support for nullable primatives with Box<T> from as-container
v0.8.6 - Fix. Forgot to stash before publishing. Stash and push what should have been v0.8.5
# Change Log

v0.9.0 - BREAKING CHANGE - API changed from JSON.parse(data, defaultValues) to JSON.parse(data). Default Values defaults to true. Large update. Refactor all the code, nullable primitives, rewrite the transform, allow extensibility with @omit keywords, and fix a plethora of bugs
v0.9.1 - Fix #71
v0.9.2 - Fix #75 + Build sizes significantly reduced
v0.9.3 - Fix #76
v0.9.4 - Fix #77
v0.9.5 - Fix #46
v0.9.6 - Fix bugs
v0.9.7 - Update testing framework and readme logo
v0.9.8 - Update dependencies
v0.9.8a - Fix #80 - Empty Maps were not serialized to {}, instead, threw memory out of bounds
v0.9.8b - Fix #81 - Revert transform
v0.9.9 - Fix #82 - Initialize maps
v0.9.9a - Remove extraneous logs from transform
v0.9.10 - Fix transform type checks. switch to nodekind checks
v0.9.11 - Remove MpZ--implement custom serializers and deserializers in the works
v0.9.12 - Add compat with aspect
v0.9.13 - Fix empty strings not indexing correctly
v0.9.14 - Ignore properties of type Function
v0.9.15 - Support JSON.Raw blocks
v0.9.16 - JSON.Raw should be completely untouched
v0.9.17 - A schema's parent's fields should be included properly
v0.9.18 - Should be able to use @alias and @omit*** or JSON.Raw
v0.9.19 - Fix arguments in @omitif declarations not working properly
v0.9.20 - Strings were being received with quotes attached via the toString functionality. Removed that.
v0.9.22 - Fix #89 and #93. Several bug fixes some severe such as ",null" being prepended when using @omit. Properly warn when a schema has fields that are not compatible with json
v0.9.23 - Comment out SIMD-related code for now
v0.9.24 - Remove transform changes from previous release
v0.9.25 - Implement JSON.parseSafe
v0.9.26 - Remove unnecessary dependencies
## UNRELEASED

[UNRELEASED] v1.0.0
- Allow nullable primitives
- Port over JSON.Value
- Performance improvements
- Add SIMD support
- Introduce options
- Custom serializers
- Support arbitrary-length integers (@hypercubed/as-mpz)
- Remove as-container (Box<T>)
- fix: allow plain `null` values during serialization [#700](https://github.com/hypermodeinc/modus/pull/700)

- fix: resolve warning in `deserializeRawMap` [#692](https://github.com/hypermodeinc/modus/pull/692)
- fix: add json serialization support for neo4j sdk types
[#699](https://github.com/hypermodeinc/modus/pull/699)

## 2025-01-09 - CLI 0.16.6
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
v0.8.2 - Properties starting with `static` or `private` would be ignored
v0.8.3 - Dirty fix to issue #68. Add __JSON_Stringify callable to global scope.
v0.8.4 - Fix #71. Classes with the extending class overriding a property cause the property to be serialized twice.
v0.8.5 - Fix #73. Support for nullable primatives with Box<T> from as-container
v0.8.6 - Fix. Forgot to stash before publishing. Stash and push what should have been v0.8.5

v0.9.0 - BREAKING CHANGE - API changed from JSON.parse(data, defaultValues) to JSON.parse(data). Default Values defaults to true. Large update. Refactor all the code, nullable primitives, rewrite the transform, allow extensibility with @omit keywords, and fix a plethora of bugs
v0.9.1 - Fix #71
v0.9.2 - Fix #75 + Build sizes significantly reduced
v0.9.3 - Fix #76
v0.9.4 - Fix #77
v0.9.5 - Fix #46
v0.9.6 - Fix bugs
v0.9.7 - Update testing framework and readme logo
v0.9.8 - Update dependencies
v0.9.8a - Fix #80 - Empty Maps were not serialized to {}, instead, threw memory out of bounds
v0.9.8b - Fix #81 - Revert transform
v0.9.9 - Fix #82 - Initialize maps
v0.9.9a - Remove extraneous logs from transform
v0.9.10 - Fix transform type checks. switch to nodekind checks
v0.9.11 - Remove MpZ--implement custom serializers and deserializers in the works
v0.9.12 - Add compat with aspect
v0.9.13 - Fix empty strings not indexing correctly
v0.9.14 - Ignore properties of type Function
v0.9.15 - Support JSON.Raw blocks
v0.9.16 - JSON.Raw should be completely untouched
v0.9.17 - A schema's parent's fields should be included properly
v0.9.18 - Should be able to use @alias and @omit*** or JSON.Raw
v0.9.19 - Fix arguments in @omitif declarations not working properly
v0.9.20 - Strings were being received with quotes attached via the toString functionality. Removed that.
v0.9.22 - Fix #89 and #93. Several bug fixes some severe such as ",null" being prepended when using @omit. Properly warn when a schema has fields that are not compatible with json
v0.9.23 - Comment out SIMD-related code for now
v0.9.24 - Remove transform changes from previous release
v0.9.25 - Implement JSON.parseSafe
v0.9.26 - Remove unnecessary dependencies
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2025 Jairus Tanaka <me@jairus.dev>
Copyright (c) 2023 Jairus Tanaka <jairus.[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
68 changes: 53 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<h5 align="center">
<pre>
<span style="font-size: 0.8em;"> ██ ███████ ██████ ███ ██ █████ ███████
██ ██ ██ ██ ████ ██ ██ ██ ██
██ ███████ ██ ██ ██ ██ ██ █████ ███████ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
█████ ███████ ██████ ██ ████ ██ ██ ███████
</span>
AssemblyScript - v1.0.0
</pre>
<pre> __ _____ _____ _____ _____ _____
__| || __|| || | | ___ | _ || __|
| | ||__ || | || | | ||___|| ||__ |
|_____||_____||_____||_|___| |__|__||_____|
v0.9.26
</pre>
</h5>

## Installation
Expand All @@ -16,10 +13,10 @@
npm install json-as
```

Add the `--transform` to your `asc` command (e.g. in package.json)
Add the transform to your `asc` command (e.g. in package.json)

```bash
--transform json-as
--transform json-as/transform
```

Alternatively, add it to your `asconfig.json`
Expand All @@ -28,7 +25,7 @@ Alternatively, add it to your `asconfig.json`
{
// ...
"options": {
"transform": ["json-as"]
"transform": ["json-as/transform"]
}
}
```
Expand Down Expand Up @@ -129,9 +126,50 @@ If you want a feature, drop an issue (and again, maybe a star). I'll likely add

## Contact

- [Email](mailto:[email protected])
- [GitHub](https://github.com/JairusSW)
- [Discord](discord.com/users/600700584038760448)
Contact me at:

Email: `[email protected]`
GitHub: `JairusSW`
Discord: `jairussw`

## Performance

Run or view the benchmarks [here](https://github.com/JairusSW/as-json/tree/master/bench)

Below are benchmark results comparing JavaScript's built-in JSON implementation and `JSON-AS`

My library beats JSON (written in C++) on all counts _and_, I see many places where I can pull at least a 60% uplift in performance if I implement it.

Note: SIMD is in-development and only available on the `v1` branch on GitHub

Serialization Benchmarks:

| Value | JavaScript (ops/s) | JSON-AS (ops/s) | JSON-AS (Pages) | JSON-AS (SIMD+Pages) | Max Throughput |
| -------------------------- | ------------------ | ------------------ | ------------------- | -------------------- | -------------- |
| "hello world" | 7,124,361 | 44,290,480 (6.2x) | 73,601,235 (10.3x) | NOT IMPLEMENTED | 1.91 GB/s |
| 12345 | 9,611,677 | 66,900,642 (6.9x) | 145,924,333 (15.2x) | NOT IMPLEMENTED | 0.58 GB/s |
| 1.2345 | 7,227,259 | 20,322,939 (2.8x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 0.16 GB/s |
| [[],[[]],[[],[[]]]] | 5,655,429 | 34,453,102 (6.0x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 1.32 GB/s |
| { x: f64, y: f64, z: f64 } | 3,878,604 | 44,557,996 (11.5x) | 113,203,242 (29.2x) | 172,023,231 (44.4x) | 8.61 GB/s |

Deserialization Benchmarks:

| Value | JavaScript (ops/s) | JSON-AS (ops/s) | Difference |
| -------------------------- | ------------------ | --------------- | ---------- |
| "hello world" | 12,210,131 | 24,274,496 | + 98% |
| "12345" | 21,376,873 | 254,640,930 | + 1,191% |
| 1.2345 | 23,193,902 | 221,869,840 | + 987% |
| [[],[[]],[[],[[]]]] | 4,777,227 | 74,921,123 | + 1,568% |
| { x: f64, y: f64, z: f64 } | 10,973,723 | 25,214,019 | + 230% |

And my PC specs:

| Component | Specification |
| -------------- | ------------------------------ |
| Wasmer Version | v4.3.0 |
| CPU | AMD Ryzen 7 7800x3D @ 6.00 GHz |
| Memory | T-Force DDR5 6000 MHz |
| OS | Ubuntu WSL2 |

## Issues

Expand Down
2 changes: 1 addition & 1 deletion as-test.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"coverage": false
},
"buildOptions": {
"args": ["--enable simd", "--runtime stub"],
"args": ["--transform ./transform"],
"target": "wasi"
},
"runOptions": {
Expand Down
4 changes: 2 additions & 2 deletions asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
}
},
"options": {
"transform": [],
"disableWarning": []
"transform": ["./transform", "as-test/transform"],
"disableWarning": [226]
},
"extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
}
1 change: 1 addition & 0 deletions assembly/__benches__/as-tral.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@as-tral/cli/as-tral" />
48 changes: 31 additions & 17 deletions assembly/__benches__/misc.bench.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import { bench } from "as-bench/assembly/bench";
import { bs } from "as-bs";
import { deserializeString_SIMD } from "../deserialize/simd/string";
import { deserializeString } from "../deserialize/simple/string";
import { bytes } from "../util/bytes";
const str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()\\\"\t\r\f\n\u0000';
const str2 = '"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()\\\\\\"\\t\\r\\f\\n\\u0000"';
const srcStart = changetype<usize>(str);
const srcEnd = srcStart + bytes(str);
bs.ensureSize(2048);
bench("Deserialize String (Simple)", () => {
deserializeString(str2);
import { JSON } from "..";
import { BRACE_LEFT, BRACKET_LEFT, CHAR_F, CHAR_T, QUOTE } from "../custom/chars";

bench("Match Type (string)", () => {
blackbox<boolean>(matchType(blackbox<string>("\""), JSON.Types.String));
});
// bench("Deserialize String (SIMD)", () => {
// (str2, bs.buffer);
// });
bench("Deserialize String (SIMD)", () => {
deserializeString_SIMD(str2, srcStart, srcEnd, __new(158, idof<string>()));

bench("Match Type (bool)", () => {
blackbox<boolean>(matchType(blackbox<string>("t"), JSON.Types.Bool));
});

bench("Match Type (array)", () => {
blackbox<boolean>(matchType(blackbox<string>("["), JSON.Types.Array));
});

bench("Match Type (struct)", () => {
blackbox<boolean>(matchType(blackbox<string>("{"), JSON.Types.Obj));
});

bench("Match Type (raw)", () => {
blackbox<boolean>(matchType(blackbox<string>("\""), JSON.Types.Raw));
});

@inline function matchType(data: string, type: JSON.Types): boolean {
const firstChar = load<u8>(changetype<usize>(data));
if (JSON.Types.String == type && firstChar == QUOTE) return true;
else if (JSON.Types.Bool == type && (firstChar == CHAR_T || firstChar == CHAR_F)) return true;
else if (JSON.Types.Array == type && firstChar == BRACKET_LEFT) return true;
else if (JSON.Types.Obj == type && firstChar == BRACE_LEFT) return true;
else if (type < 7 && type > 0 && (firstChar < 58 && firstChar > 46)) return true;
else if (JSON.Types.Raw == type) return true;
else return false;
}
2 changes: 1 addition & 1 deletion assembly/__tests__/bool.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JSON } from "../";
import { JSON } from "json-as";
import { describe, expect, run } from "as-test/assembly";

describe("Should serialize booleans", () => {
Expand Down
32 changes: 0 additions & 32 deletions assembly/__tests__/simd/string.spec.ts

This file was deleted.

Loading

0 comments on commit a61c068

Please sign in to comment.