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

Optimize in ByteString to prevent excessive object allocation #1034

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and what APIs have changed, if applicable.

## [Unreleased]

## [29.62.1] - 2024-11-05
- Enhancements in ByteString and its ByteIterator to reduce object allocation

## [29.62.0] - 2024-10-28
- Check and take configurable action for invalid partition weight

Expand Down Expand Up @@ -5755,7 +5758,8 @@ patch operations can re-use these classes for generating patch messages.

## [0.14.1]

[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.62.0...master
[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.62.1...master
[29.62.1]: https://github.com/linkedin/rest.li/compare/v29.62.0...v29.62.1
[29.62.0]: https://github.com/linkedin/rest.li/compare/v29.61.0...v29.62.0
[29.61.0]: https://github.com/linkedin/rest.li/compare/v29.60.0...v29.61.0
[29.60.0]: https://github.com/linkedin/rest.li/compare/v29.59.0...v29.60.0
Expand Down
14 changes: 7 additions & 7 deletions data/src/main/java/com/linkedin/data/ByteString.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ private ByteIterator copy()
return new ByteIterator(this);
}

private void fillFromAnother(ByteIterator other) {
_currentByteArray = other._currentByteArray;
_currentByteIndex = other._currentByteIndex;
_finished = other._finished;
}

private void next()
{
//Shift the internal pointer to the next byte.
Expand Down Expand Up @@ -737,9 +743,6 @@ public int indexOfBytes(byte[] targetBytes)
//This is a reference on where to resume in case we get a mismatch.
ByteIterator resumeByteIterator = byteIterator.copy();

//We skip the first since byteIterator will begin there.
resumeByteIterator.next();

for (int i = 0; i < targetBytes.length;)
{
//If we have exhausted everything in the ByteString, then we return -1.
Expand All @@ -754,11 +757,8 @@ public int indexOfBytes(byte[] targetBytes)
//There was a mismatch so we reset i and prepare to start over.
i = 0;
//Update byteIterator to point to the next byte where our comparison will begin.
byteIterator = resumeByteIterator;
//Keep track of where to resume in the future.
resumeByteIterator = resumeByteIterator.copy();
//Skip the next since byteIterator will begin there.
resumeByteIterator.next();
byteIterator.fillFromAnother(resumeByteIterator);
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=29.62.0
version=29.62.1
group=com.linkedin.pegasus
org.gradle.configureondemand=true
org.gradle.parallel=true
Expand Down
Loading