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

V2: Speed up reflect with classes #837

Merged
merged 1 commit into from
May 10, 2024

Conversation

timostamm
Copy link
Member

Following #836, we can make another performance improvement by using classes for ReflectMessage, ReflectList and ReflectMap:

- fromBinary perf-payload.bin x 5,094 ops/sec ±0.51% (97 runs sampled)
+ fromBinary perf-payload.bin x 7,040 ops/sec ±0.67% (98 runs sampled)

// prettier-ignore
type ReflectGetValue<Field extends DescField = DescField> = (
export type ReflectGetValue<Field extends DescField = DescField> = (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't infer all types with a class implementation, so we have to export this type. Another disadvantage is that classes are more verbose, hence the small bump in bundle size.

@@ -224,64 +278,88 @@ function assertOwn(owner: Message, member: DescField | DescOneof) {
export function reflectList<V>(
field: DescField & { fieldKind: "list" },
unsafeInput?: unknown[],
check = true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new, and not final yet, see existing comment on line 51. We're not using it yet.

@timostamm timostamm merged commit 8f0a454 into v2 May 10, 2024
7 checks passed
@timostamm timostamm deleted the tstamm/speed-up-reflect-with-classes branch May 10, 2024 15:55
@timostamm timostamm mentioned this pull request May 13, 2024
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.

3 participants