-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation of deserialize transform
- Loading branch information
Showing
26 changed files
with
1,700 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,19 @@ | ||
import { deserializeString_SIMD } from "../deserialize/simd/string"; | ||
import { serializeString_SIMD } from "../serialize/simd/string"; | ||
import { bench } from "as-bench/assembly/index"; | ||
import { serialize_simple } from "../serialize/simple"; | ||
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"'; | ||
|
||
// bench("Serialize String (Simple)", () => { | ||
// serializeString(str); | ||
// }); | ||
|
||
// bench("Serialize String (BS)", () => { | ||
// serializeString_BS(str); | ||
// bs.reset(); | ||
// }); | ||
|
||
@json | ||
class Vec3 { | ||
x: i32 = 1; | ||
y: i32 = 2; | ||
z: i32 = 3; | ||
|
||
__SERIALIZE(ptr: usize = 0): string { | ||
if (ptr == 0) ptr = changetype<usize>(this); | ||
let out = `{"x":${load<i32>(ptr, offsetof<this>("x")).toString()},"y":${load<i32>(ptr, offsetof<this>("y")).toString()},"z":${load<i32>(ptr, offsetof<this>("z")).toString()},`; | ||
store<u16>(changetype<usize>(out) + ((out.length - 1) << 1), 125); | ||
return out; | ||
} | ||
|
||
__SERIALIZE_BS(ptr: usize = 0): void { | ||
ptr = ptr || changetype<usize>(this); | ||
bs.ensureSize(128); | ||
store<u64>(bs.offset, 9570664606466171); | ||
store<u16>(bs.offset, 58, 8); | ||
bs.offset += 10; | ||
|
||
serialize_simple<i32>(load<i32>(ptr, offsetof<this>("x"))); | ||
|
||
store<u64>(bs.offset, 9570668901433388); | ||
store<u16>(bs.offset, 58, 8); | ||
bs.offset += 10; | ||
|
||
serialize_simple<i32>(load<i32>(ptr, offsetof<this>("y"))); | ||
|
||
store<u64>(bs.offset, 9570673196400684); | ||
store<u16>(bs.offset, 58, 8); | ||
bs.offset += 10; | ||
|
||
serialize_simple<i32>(load<i32>(ptr, offsetof<this>("z"))); | ||
|
||
store<u16>(bs.offset, 125); | ||
bs.offset += 2; | ||
} | ||
} | ||
|
||
const vec: Vec3 = { | ||
x: 1, | ||
y: 2, | ||
z: 3 | ||
} | ||
|
||
bench("Serialize Object (New)", () => { | ||
vec.__SERIALIZE_BS(changetype<usize>(vec)); | ||
bs.out<string>(); | ||
const srcStart = changetype<usize>(str); | ||
const srcEnd = srcStart + bytes(str); | ||
bs.ensureSize(2048); | ||
bench("Deserialize String (Simple)", () => { | ||
deserializeString(str2); | ||
}); | ||
|
||
// bench("Serialize Object (Old)", () => { | ||
// vec.__SERIALIZE(changetype<usize>(vec)); | ||
// }); | ||
// } | ||
|
||
// const out = new ArrayBuffer(256); | ||
// bench("Serialize String (SIMD)", () => { | ||
// // ~5.07GB/s | ||
// serializeString_SIMD(str, changetype<usize>(out)); | ||
// }); | ||
|
||
// bench("Deserialize String (SIMD)", () => { | ||
// // ~4.03GB/s | ||
// deserializeString_SIMD(str2, changetype<usize>(out)); | ||
// (str2, bs.buffer); | ||
// }); | ||
bench("Deserialize String (SIMD)", () => { | ||
deserializeString_SIMD(str2, srcStart, srcEnd, __new(158, idof<string>())); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { snip_fast } from "../../custom/util"; | ||
import { strToInt } from "../../util/strToInt"; | ||
|
||
// @ts-ignore: Decorator valid here | ||
@inline export function deserializeInteger<T>(data: string): T { | ||
// @ts-ignore | ||
return snip_fast<T>(data); | ||
} | ||
|
||
// @ts-ignore: Decorator valid here | ||
@inline export function deserializeInteger_NEW<T>(srcStart: usize, srcEnd: usize): T { | ||
return strToInt<T>(srcStart, srcEnd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.