-
Notifications
You must be signed in to change notification settings - Fork 863
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
Avoid creating unnecessary intermediate strings #3439
Avoid creating unnecessary intermediate strings #3439
Conversation
d4bf134
to
6835027
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix typo
generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt
Outdated
Show resolved
Hide resolved
generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt
Outdated
Show resolved
Hide resolved
This change would be awesome, I spotted this a few months back, basically all JSON APIs are using triple the necessary memory for the request body. |
+1 to fixing the typo, otherwise change looks okay. I'm running a version of this branch with the typo fix through our build system, will approve if it passes the dry-run. |
The change caused some existing unit tests to fail in our build system. I'll need to take a look at why this is the case |
Is this something I can have a look at? |
If you wanted to take a look that'd be great. I'm caught up in something else right now, but here are the failed tests
All of the failures have the same error message
I haven't had the chance to investigate further yet. |
Are, by any chance, the tests failing only on .NET Framework? Because |
Yup the tests are only failing in .NET Framework. Looks like your change addresses the issue. I'll run it through our system once more once you feel it is ready. |
Check if the new version passes all tests. I haven't figured out how to run the code generation and tests. |
I'm running your latest commit through our build system. Can you also rebase your branch on top of We don't have a guide for external contributors yet, but this is how I usually make changes to the generator:
At this point, you should be able to open the |
Replaced StringWriter with MemoryStream and StreamWriter for JSON serialization to improve efficiency. JsonWriter is now initialized with StreamWriter. Adjusted indentation levels in ProcessStructure and ProcessMembers methods. Final request content is now obtained as a byte array from MemoryStream.
…nRPCRequestMarshaller.tt Co-authored-by: Stuart Lang <stuart.b.lang@gmail.com>
…nRPCRequestMarshaller.tt Co-authored-by: Stuart Lang <stuart.b.lang@gmail.com>
Refactor the instantiation of the `StreamWriter` object within a `using` statement by removing unnecessary parameters. The original code included `null` for encoding, `-1` for buffer size, and `true` for leaving the stream open. The updated code uses the default constructor, which only requires the `MemoryStream` object, as the default behavior is sufficient for the intended use case.
144b8dc
to
ee45001
Compare
Hi @dscpinheiro, I've rebased on It would be nice if building would run the templates. Beware that there are NuGet packages with known vulnerabilities being referenced. |
With this change we are losing the setting of public class InvariantCultureStreamWriter : StreamWriter
{
public InvariantCultureStreamWriter (Stream stream)
: base(stream)
{
}
public override IFormatProvider FormatProvider
{
get
{
return CultureInfo.InvariantCulture;
}
}
} |
Probably the safest option. Have any of the tests failed? I thought this was used only with JSON and XML writers that already take care of this. |
@peterrsongg and @dscpinheiro can speak for the state of the tests. They asked me to take pass because they were concerned about the |
It's a safe and small overhead. Where do you want me to put it? |
None of the tests failed, but our integration tests do not validate different cultures at the moment. You can put the file Norm mentioned in this location: https://github.com/aws/aws-sdk-net/tree/v4-development/sdk/src/Core/Amazon.Runtime/Internal/Util |
Done! |
Introduce InvariantCultureStreamWriter class to enforce invariant culture formatting. Replace StreamWriter with InvariantCultureStreamWriter in JsonRPCRequestMarshaller.tt to ensure consistent JSON formatting regardless of system culture.
Addresses #3415
Types of changes
Checklist
License
/cc @bhoradc