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

Feature Request: add options to limit generating encode and decode methods to only specific message types #1084

Closed
akrennmair opened this issue Aug 9, 2024 · 5 comments

Comments

@akrennmair
Copy link
Contributor

I'm facing the specific problem that a significant amount of the generated script size of a project mine consists of scripts generated by ts-proto. I was looking into limiting what is being generated, and found the outputEncodeMethods option to be too limited: generally speaking, I have two top-level types, and for one (the request type) I only want to generate an encode method, while for the other (the response type), I only want to generate a decode method.

I would therefore like to have options to limit the generation of encode resp. decode methods to only specific types. A similar suggestion has also been made as a comment to #773: #773 (comment)

I also have a branch in which I implemented a possible solution that simply regular expressions. I'm not sure though whether this is sufficient as a general solution. I will submit a PR for it.

@stephenh
Copy link
Owner

Hi @akrennmair ; thanks for the PR! I guess that makes sense...

Out of curiosity, for your use case, is each type only primitives? Or does it have other messages?

I.e. I could see something like:

  • message Person -> you want to encode Person, but
  • message Person has a address = Address field and a pets = repeated Pet field

Such that to "encode Person", you actually end up ending encode methods for ~4-5 different messages, which seems like it would make keeping the regex updated kind of tedious? Or do you think that wouldn't be a problem?

@akrennmair
Copy link
Contributor Author

@stephenh the way we structure our messages is through nested message types, so we do have more complex structures in there, but they're all underneath our request message type, so they'd be automatically covered by a regex just matching for a prefix. I updated one of the integration tests to specifically demonstrate that: https://github.com/stephenh/ts-proto/pull/1085/files#diff-1039be2c30dc2bd6576bdf8e7acd59bee9e3bf408cf023373f9bf2241d675a69

I have been thinking as well whether it could become too tedious to manually manage the regular expression, so I wonder whether it would also makes sense to add inverted options, i.e. output{Encode,Decode}ExcludeTypes where any types matching that regex would not have their encode resp. decode methods generated.

@stefan-koshiw
Copy link

Hi @stephenh

Could you take a look at the associated PR: #1085 and tell us what needs to be done to get this merged? We found that this would greatly reduce the size of the generated code and that would help us close a perf issue that we currently have, so getting this merged would be awesome! :)

@stephenh
Copy link
Owner

stephenh commented Dec 1, 2024

Hi @stefan-koshiw , thanks for the ping; #1085 does lgtm. For some reason I don't see the "Approve & Run" button that I usually click for PRs to have the GitHub actions run -- @akrennmair can you try rebasing/updating your PR, and see if that fixes things? Once I can get the CI build passing, it lgtm and we can merge it. Thanks!

stephenh pushed a commit that referenced this issue Dec 3, 2024
… only specific message types (#1085)

I created this PR as a possible to solution to the feature request
submitted in #1084.

I added integration tests for test coverage, and updated the
documentation to include the two new options.
@stephenh
Copy link
Owner

stephenh commented Dec 3, 2024

Fixed in #1085 , thanks @akrennmair !

@stephenh stephenh closed this as completed Dec 3, 2024
stephenh pushed a commit that referenced this issue Dec 3, 2024
# [2.5.0](v2.4.2...v2.5.0) (2024-12-03)

### Features

* Add options to limit generation of encode and decode methods to only specific message types ([#1085](#1085)) ([c7372fa](c7372fa)), closes [#1084](#1084)
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

No branches or pull requests

3 participants