Skip to content

Commit

Permalink
perf: Generating "else if" where applicable (#1141)
Browse files Browse the repository at this point in the history
In oneof scenarios, this commit proposes generating "else if" statements
where applicable.

The original idea was an attempt to speed up Typescript compilation by
reducing the amount of paths Typescript can analyze. Spoiler alert =>
nothing changes from that point of view.

The compilation of my [proto
file](https://github.com/workadventure/workadventure/blob/develop/messages/protos/messages.proto)
takes between 41 and 44 seconds with and without "else if" statements.

Still, the "else if" conditions should slightly speed up the runtime
execution, by avoiding unnecessary checks to the Javascript runtime.

This PR is directly linked to
#1135
Note: in #1135, @stephenh you
recommend trying to use a switch statement (instead of "else if"). This
would require a really big refactoring and I'm not familiar enough with
the code base to attempt that.
The "else if" implementation was a bit of a low hanging fruit.

I still think the "//ts-nocheck" annotation would be really useful and
is the way to go, since it would simply take "0 seconds" to typecheck
the generated file (you can't beat 0 in terms of performance 😆
)
  • Loading branch information
moufmouf authored Nov 26, 2024
1 parent 2dfe112 commit 4a8018c
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 142 deletions.
30 changes: 10 additions & 20 deletions integration/oneof-unions-snake/google/protobuf/struct.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 16 additions & 20 deletions integration/oneof-unions-value/google/protobuf/struct.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 26 additions & 28 deletions integration/oneof-unions-value/oneof.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 14 additions & 20 deletions integration/oneof-unions/google/protobuf/struct.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 20 additions & 28 deletions integration/oneof-unions/oneof.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a8018c

Please sign in to comment.