Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rework typescript generator & add suite #46

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

MrFoxPro
Copy link

@MrFoxPro MrFoxPro commented Sep 13, 2024

Closes #43
Probably needs more tests
Checkout suite/typescript/ts/test.ts and suite/typescript/readme.md for example usage and additional information
You can fix and adjust as you want if you have time

Benchamrks:

Encode

┌─────────┬───────────────────────────────┬─────────────┬────────────────────┬──────────┬─────────┐
│ (index) │ Task Name                     │ ops/sec     │ Average Time (ns)  │ Margin   │ Samples │
├─────────┼───────────────────────────────┼─────────────┼────────────────────┼──────────┼─────────┤
│ 0       │ 'serdegen-bincode:encode'     │ '717,309'   │ 1394.0992784144942 │ '±0.31%' │ 1075964 │
│ 1       │ 'JSON:encode'                 │ '384,683'   │ 2599.5422867295706 │ '±0.05%' │ 577025  │
│ 2       │ 'protobuf-js-ts-proto:encode' │ '1,049,439' │ 952.8891828025206  │ '±0.50%' │ 1574160 │
└─────────┴───────────────────────────────┴─────────────┴────────────────────┴──────────┴─────────┘

Decode

┌─────────┬───────────────────────────────┬───────────┬────────────────────┬──────────┬─────────┐
│ (index) │ Task Name                     │ ops/sec   │ Average Time (ns)  │ Margin   │ Samples │
├─────────┼───────────────────────────────┼───────────┼────────────────────┼──────────┼─────────┤
│ 0       │ 'serdegen-bincode:decode'     │ '894,259' │ 1118.2439247680838 │ '±0.24%' │ 1341389 │
│ 1       │ 'JSON:decode'                 │ '460,448' │ 2171.7932150326965 │ '±0.14%' │ 690674  │
│ 2       │ 'protobuf-js-ts-proto:decode' │ '837,149' │ 1194.5301794026077 │ '±0.18%' │ 1255724 │
└─────────┴───────────────────────────────┴───────────┴────────────────────┴──────────┴─────────┘

Need investigation how to improve encoding.
It's worth to look into protobuf-js implementation

@MrFoxPro MrFoxPro mentioned this pull request Sep 13, 2024
@ma2bd
Copy link
Contributor

ma2bd commented Sep 14, 2024

Thanks @MrFoxPro for your work. It looks like the lint error is on main but the test compilation error is yours.

@MrFoxPro
Copy link
Author

Thanks @MrFoxPro for your work. It looks like the lint error is on main but the test compilation error is yours.

Yep, PR requires some polishing

@MrFoxPro
Copy link
Author

MrFoxPro commented Sep 14, 2024

I thought one way to speedup encoding is to preallocate chunk for fixed-size values of type by recursive lookup of it in code generator and adding flag to "noAlloc" in writeX functions

@MrFoxPro
Copy link
Author

MrFoxPro commented Oct 1, 2024

I decided to change TypeScript implementation. Now it looks like this:

enum MultiEnum {
	VariantA(i32),
	VariantB(String),
	VariantC { x: u8, y: f64 },
	UnitVariant,
}
struct ComplexStruct {
	inner: SimpleStruct,
	flag: bool,
	items: Vec<MultiEnum>,
	unit: UnitStruct,
	newtype: NewtypeStruct,
	tuple: TupleStruct,
	tupple_inline: (String, i32),
	map: HashMap<i32, i64>
}

->

export const ComplexStruct_obj: Registry.ComplexStruct = {
	inner: { a: 42, b: "Hello" },
	flag: true,
	items: [
		{ $: "variant_a", $0: 10 },
		{ $: "variant_b", $0: "World" }
	],
	unit: null,
	newtype: 99,
	tuple: { $0: 123, $1: 45.67, $2: "Test" },
	tupple_inline: { $0: "SomeString", $1: 777 },
	map: new Map().set(3, 7n)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Improve TypeScript generator
2 participants