Skip to content

feat: rework typescript generator & add suite #46

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

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

Conversation

MrFoxPro
Copy link
Contributor

@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 requested a review from ma2bd as a code owner September 13, 2024 02:32
@MrFoxPro MrFoxPro mentioned this pull request Sep 13, 2024
@MrFoxPro MrFoxPro force-pushed the typescript-rework branch 2 times, most recently from 9a6ea57 to 6c2f861 Compare September 13, 2024 16:51
@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
Contributor 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
Contributor 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
Contributor 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)
}

@MrFoxPro MrFoxPro force-pushed the typescript-rework branch from 9e0642e to 145392e Compare March 9, 2025 08:11
@MrFoxPro
Copy link
Contributor Author

MrFoxPro commented Mar 9, 2025

I updated to bincode 2, but I'm not sure about it. There are some breaking changes that could lead to potential problems in javascript encoder/decoder

@MrFoxPro
Copy link
Contributor Author

MrFoxPro commented Mar 9, 2025

@ma2bd what dou you think about this PR? Maybe it's better to move my implementation in separate crate and repository?

@MrFoxPro
Copy link
Contributor Author

MrFoxPro commented Mar 9, 2025

@MrFoxPro
Copy link
Contributor Author

MrFoxPro commented Mar 9, 2025

Yes, bincode v2 format is different from v1

@ma2bd
Copy link
Contributor

ma2bd commented Mar 30, 2025

@MrFoxPro Thanks for the PR.

  • This seems like a big change: I'm going to have to ask existing JS/TS users.
  • Bincode2 is probably too much if this is breaking

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