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

Make rpc serialization chunk size configurable #9961

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public final class ServerSerializationStreamWriter extends
* array literals.
*/
public static class LengthConstrainedArray {
public static final int MAXIMUM_ARRAY_LENGTH = 1 << 15;
private static final String POSTLUDE = "])";
private static final String PRELUDE = "].concat([";

private final StringBuffer buffer;
private final int maximumArrayLength = Integer.getInteger("gwt.rpc.maxPayloadChunkSize", 1 << 15);
Copy link
Member

Choose a reason for hiding this comment

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

Keep this static? It should only need to be read once (and used consistently afterwards)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes true, that was my initial change but then I looked at the gtw.rpc.version property which does seem runtime configurable. I can change it back to static if you want.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that makes sense. System.getProperty is a blocking call on older JVMs, but at least on Java 11 this is replaced by a ConcurrentHashMap.

I suspect the reason that GWT historically looked up the value on each call is to allow the SerializationException to be thrown when a call was made, rather than when the class was initialized, since the range of accepted values could change release to release.

I think I'm fine leaving this max size as a runtime lookup, as you have it written.

Will leave the PR open a bit longer for any other thoughts on the matter.

private int count = 0;
private boolean needsComma = false;
private int total = 0;
Expand All @@ -68,8 +68,8 @@ public LengthConstrainedArray(int capacityGuess) {

public void addToken(CharSequence token) {
total++;
if (count++ == MAXIMUM_ARRAY_LENGTH) {
if (total == MAXIMUM_ARRAY_LENGTH + 1) {
if (count++ == maximumArrayLength) {
if (total == maximumArrayLength + 1) {
buffer.append(PRELUDE);
javascript = true;
} else {
Expand Down Expand Up @@ -106,7 +106,7 @@ public void setJavaScript(boolean javascript) {

@Override
public String toString() {
if (total > MAXIMUM_ARRAY_LENGTH) {
if (total > maximumArrayLength) {
return "[" + buffer.toString() + POSTLUDE;
} else {
return "[" + buffer.toString() + "]";
Expand Down