Skip to content

reduce bytes used when serializing Extent #52549

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

Merged
merged 5 commits into from
Feb 24, 2020
Merged
Changes from 4 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
36 changes: 20 additions & 16 deletions server/src/main/java/org/elasticsearch/common/geo/Extent.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,31 @@ static void readFromCompressed(ByteArrayDataInput input, Extent extent) {
posRight = Integer.MIN_VALUE;
break;
case POSITIVE_SET:
posRight = input.readVInt();
posLeft = Math.toIntExact(posRight - input.readVLong());
posLeft = input.readVInt();
posRight = Math.toIntExact(input.readVLong() + posLeft);
negLeft = Integer.MAX_VALUE;
negRight = Integer.MIN_VALUE;
break;
case NEGATIVE_SET:
negRight = input.readInt();
negRight = -input.readVInt();
negLeft = Math.toIntExact(negRight - input.readVLong());
posLeft = Integer.MAX_VALUE;
posRight = Integer.MIN_VALUE;
break;
case CROSSES_LAT_AXIS:
posRight = input.readInt();
negLeft = Math.toIntExact(posRight - input.readVLong());
posRight = input.readVInt();
negLeft = -input.readVInt();
posLeft = 0;
negRight = 0;
break;
default:
posRight = input.readVInt();
posLeft = Math.toIntExact(posRight - input.readVLong());
negRight = input.readInt();
case ALL_SET:
posLeft = input.readVInt();
posRight = Math.toIntExact(input.readVLong() + posLeft);
negRight = -input.readVInt();
negLeft = Math.toIntExact(negRight - input.readVLong());
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably update ALL_SET to have the same logic as POSITIVE_SET and NEGATIVE_SET combined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to what I think you meant

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I was thinking of doing this:

                posLeft = input.readVInt();
                posRight =  Math.toIntExact(input.readVLong() + posLeft);
                negRight = -input.readVInt();
                negLeft = Math.toIntExact(negRight - input.readVLong());

There is no reason to serialize posLeft/posRight differently in the POSITIVE_SET case or in the ALL_SET case? And likewise for negLeft/negRight in the NEGATIVE_SET or ALL_SET cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad. I misunderstood. will update thanks

break;
default:
throw new IllegalArgumentException("invalid extent values-set byte read [" + type + "]");
}
extent.reset(top, bottom, negLeft, negRight, posLeft, posRight);
}
Expand Down Expand Up @@ -165,23 +167,25 @@ void writeCompressed(ByteBuffersDataOutput output) throws IOException {
switch (type) {
case NONE_SET : break;
case POSITIVE_SET:
output.writeVInt(this.posRight);
output.writeVInt(this.posLeft);
output.writeVLong((long) this.posRight - this.posLeft);
break;
case NEGATIVE_SET:
output.writeInt(this.negRight);
output.writeVInt(-this.negRight);
output.writeVLong((long) this.negRight - this.negLeft);
break;
case CROSSES_LAT_AXIS:
output.writeInt(this.posRight);
output.writeVLong((long) this.posRight - this.negLeft);
break;
default:
output.writeVInt(this.posRight);
output.writeVInt(-this.negLeft);
break;
case ALL_SET:
output.writeVInt(this.posLeft);
output.writeVLong((long) this.posRight - this.posLeft);
output.writeInt(this.negRight);
output.writeVInt(-this.negRight);
output.writeVLong((long) this.negRight - this.negLeft);
break;
default:
throw new IllegalArgumentException("invalid extent values-set byte read [" + type + "]");
}
}

Expand Down