-
Notifications
You must be signed in to change notification settings - Fork 2.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
[MNG-7899] Various memory usage improvements 4 #1269
Conversation
861346b
to
607b420
Compare
607b420
to
ef8c0dd
Compare
Memory allocation profiling using ConsoleMavenTransferListener_memalloc_Test.java calling the ConsoleMavenTransferListener class 100 million times. This test shows a drastic decrease of :
The elapse time during the test execution show a 50% reduction, ~100 seconds for the initial code and ~50 seconds for the optimised code. Here the JMC capture for the initial code (file available here) Here the JMC capture for the optimised code (file available here) To reproduce:
|
495d5e7
to
06eb372
Compare
@sebastien-doyon unit tests seem broken. |
Also, #1268, #1269 and #1270 really look related to the same goal, I.e. optimize the logging, so I think they should be merged in order to have a better understand of the benefits (even if they could be 3 different commits). |
@gnodet yes, I am trying to find the problem, but without access to the surefire report files, it is hard to find the problem. Do you have access or know how to get access to the target directory of a build in github? That would help debug.
I think the PR 1279 is complementary with this PR. The only change in the 1279 PR that would be needed is to add back the
If you think, I was trying to separate unrelated changes so the obvious ones could be merged while those with problems or comments could be worked out separately, like this one. Tell me if you really prefer me to merge in on PR. |
a1cb4fa
to
27b7a6b
Compare
@gnodet the last commit fixes the unit test that was broken. |
Merging the getStatus() method to optimize : - Use the main StringBuilder to append string instead of using a separate one - Use the StringBuilder.append() with index to avoid String.substring(), less temporary strings - Reuse the FileSizeFormat object in the while loop avoiding multiple temporary instances creation
- Non-threadsafe FileSizeFormat instance can be make class instance since its formatProgress() method is only called in a synchronized block. - add a test in a multi-threaded context
27b7a6b
to
730d0b5
Compare
maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java
Outdated
Show resolved
Hide resolved
- Non-threadsafe StringBuilder instance 'buffer' can be make class instance since it is always called in synchronized methods - remove synchronized block in transferProgressed() method, the method is synchronized and the block is not needed
- Remove the Collections.synchronizedMap since all methods that use the transfers map are synchronized
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.
LGTM
There are still a couple of things to clean in this package....
- FileSizeFormat should be moved to top level
- it should be refactored to accept an
Appender
as argument BatchModeMavenTransferListener
should be removedSlf4jMavenTransferListener
should inheritAbstractMavenTransferListener
AbstractMavenTransferListener
uses direct ansi sequences (this will be fixed in [MNG-7995] Switch to JLine to provide line editing #1279)
@sebastien-doyon feel free to work on these issues if you're fancy
buffer.append(" ("); | ||
} | ||
|
||
buffer.append(format.formatProgress(complete, total)); |
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.
I wonder if the FileSizeFormat
should be refactored to be given a StringBuffer
to write into, instead of (or in addition to) the current methods.
But this may be for another PR...
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.
Done in the last commit
Done in the last commit
Done in the last commit, the
Done in the last commit
I leave this one for another PR, I suggest transform the |
https://issues.apache.org/jira/browse/MNG-7899
Merging the getStatus() method to optimize :
separate one
less temporary strings
temporary instances creation
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
[ X] I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
[X ] In any other case, please file an Apache Individual Contributor License Agreement.