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

[c#] Moved all message allocations to CreateTemplate(), making it easier to e.g. use pools to prevent GC load. #7722

Closed

Conversation

ManuelKugelmann
Copy link

@ManuelKugelmann ManuelKugelmann commented Jul 16, 2020

fixes #6401

Moves all message allocations to CreateTemplate(), making it easier to e.g. use pools to prevent GC load.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@ManuelKugelmann ManuelKugelmann changed the title fix issue #6401 - replace new by Parser.CreateTemplate [c#] fix issue #6401 - replace new by Parser.CreateTemplate Jul 16, 2020
@ManuelKugelmann ManuelKugelmann changed the title [c#] fix issue #6401 - replace new by Parser.CreateTemplate [c#] Moved all message allocations to CreateTemplate(), making it easier to e.g. use pools to prevent GC load. Jul 16, 2020
@ManuelKugelmann
Copy link
Author

ManuelKugelmann commented Jul 16, 2020

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@@ -104,7 +104,7 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) {
variables_,
"if (other.$has_property_check$) {\n"
" if ($has_not_property_check$) {\n"
" $property_name$ = new $type_name$();\n"
" $property_name$ = $type_name$.Parser.CreateTemplate();\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

after changing the codegen, you'd also need to regenerate the code in this repository.

Copy link
Author

@ManuelKugelmann ManuelKugelmann Jul 20, 2020

Choose a reason for hiding this comment

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

= do a build ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Build and then run https://github.com/protocolbuffers/protobuf/blob/master/csharp/generate_protos.sh.

The updates to the generated files need to be commited (preferrably as a separate commit)

@jtattermusch
Copy link
Contributor

jtattermusch commented Jul 17, 2020

CC @JamesNK @jskeet

@jtattermusch jtattermusch self-assigned this Jul 17, 2020
@@ -60,7 +60,7 @@ internal MessageParser(Func<IMessage> factory, bool discardUnknownFields, Extens
/// Creates a template instance ready for population.
/// </summary>
/// <returns>An empty message.</returns>
internal IMessage CreateTemplate()
public IMessage CreateTemplate()
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -104,7 +104,7 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) {
variables_,
"if (other.$has_property_check$) {\n"
" if ($has_not_property_check$) {\n"
" $property_name$ = new $type_name$();\n"
" $property_name$ = $type_name$.Parser.CreateTemplate();\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the overhead of using Parser.CreateTemplate?

@jtattermusch
Copy link
Contributor

Is there a good way of checking that we haven't missed any occurrences of new XYZMessage() in the code?

@jtattermusch
Copy link
Contributor

One potential concern is that if this gets merged, the newly generated code won't be compatible with the older runtimes anymore (there is no public CreateTemplate() method).
While that is fine and understandable limitation, it would still be better if this change is bundled with other changes that also require runtime upgrade once code is regenerated, to amortize the cost of potentially disrupting user's workflow over multiple features. This feature in isolation is quite a niche case so I'm not sure the benefits outweigh the costs.

@acozzette
Copy link
Member

@ManuelKugelmann I am going to close this since there has been no activity in a long time, but please feel free to comment here if you would like to pick this up again.

@ahmednfwela
Copy link

@jtattermusch I have issued #19776 to only change the visibility of the CreateTemplate() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants