-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8346239: Improve memory efficiency of JimageDiffGenerator #22835
Conversation
👋 Welcome back sgehwolf! A progress list of the required criteria for merging this PR into |
@jerboaa This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 57 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@MBaesken @RealFYang Could you please test this PR since you originally ran into JDK-8346239 (this bug) and JDK-8344036. Thanks! |
Yes, I can confirm that it works on my linux-aarch64 platform. Great! Thanks! |
Hi Severin, I added it to our build/test queue. |
Thank you! |
Thanks, Matthias! |
Thanks for the review @MBaesken! |
/integrate |
Going to push as commit f696d9c.
Your commit was automatically rebased without conflicts. |
@slowhog Would it be possible to do a pass over this too? |
try { | ||
try (is1; is2) { | ||
while ((bytesRead1 = is1.read(buf1)) != -1 && | ||
(bytesRead2 = is2.read(buf2)) != -1) { |
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.
- what's the point to have second try block?
- I think it's easier to read to while loop on is1, then read and check is2 within the loop instead of && on both.
try (is1; is2) { | ||
while ((bytesRead1 = is1.read(buf1)) != -1 && | ||
(bytesRead2 = is2.read(buf2)) != -1) { | ||
if (bytesRead1 != bytesRead2) { |
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.
This test seems to assume there won't be any short reads. That might be true in practice, but for defensive programming reasons it would be safer to use readNBytes()
instead of read()
.
if (bytesRead1 != bytesRead2) { | ||
return false; | ||
} | ||
if (bytesRead1 == buf1.length) { |
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.
This can be simplified by using Arrays.equals(byte[],int,int,byte[],int,int)
for both cases.
Sorry, I didn't realize this PR was already closed. You can treat my comments as "FYI". |
Thanks for the reviews. I'll follow up with those comments/fixes in a separate PR. |
@slowhog @AlanBateman @archiecobbs Clean ups done in #23014 PTAL. |
Please review this fairly simple change to improve how the
JimageDiffGenerator
works. The original implementation is pretty naive and read all bytes into memory and then compared them. This improved version only reads bytes on a bound buffer into memory compares those bytes and if equal continues on to reading the next bytes (2k
at most) at a time. Previously it was2*N
(whereN
is the file size of a file in bytes) part of the JDK. Ouch.There is still the off-chance of reading a full file into memory when the generator detects a change, but this shouldn't happen for large files since the total diff should be around
600K
as of today.This also reverts changes from JDK-8344036 other than the
/timeout
change to the test, which is preserved as I think this bump is no longer needed.Testing:
--with-native-debug-symbols=internal
(so as to have a large libjvm.so).Thoughts?
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22835/head:pull/22835
$ git checkout pull/22835
Update a local copy of the PR:
$ git checkout pull/22835
$ git pull https://git.openjdk.org/jdk.git pull/22835/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22835
View PR using the GUI difftool:
$ git pr show -t 22835
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22835.diff
Using Webrev
Link to Webrev Comment