Skip to content

V2: Speed up reflect with classes#837

Merged
timostamm merged 1 commit intov2from
tstamm/speed-up-reflect-with-classes
May 10, 2024
Merged

V2: Speed up reflect with classes#837
timostamm merged 1 commit intov2from
tstamm/speed-up-reflect-with-classes

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.

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 requested a review from srikrsna-buf May 10, 2024 15:05
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