-
Notifications
You must be signed in to change notification settings - Fork 4
Reduce memory pressure in FormattingTestReporter #737
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
Conversation
Generate changelog in
|
✅ Successfully generated changelog entry!What happened?Your changelog entries have been stored in the database as part of our migration to ChangelogV3. Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. |
...in/groovy/com/palantir/witchcraft/java/logging/gradle/testreport/FormattingTestReporter.java
Outdated
Show resolved
Hide resolved
...in/groovy/com/palantir/witchcraft/java/logging/gradle/testreport/FormattingTestReporter.java
Outdated
Show resolved
Hide resolved
| lineProcessor.accept(line, delegate); | ||
| delegate.write("\n"); |
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.
Do we need to synchronize on the writer to ensure this is written atomically?
| lineProcessor.accept(line, delegate); | |
| delegate.write("\n"); | |
| synchronized (this) { | |
| lineProcessor.accept(line, delegate); | |
| delegate.write('\n'); | |
| } |
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.
if we're going to make this LineProcessingWriter thread-safe, then I think we need to protect the lineBuffer from concurrent writes, and maybe then add synchronized keyword to the write() and close() methods.
I'm not sure we need it to be thread-safe though... even multiple calls to the writeAllOutput method here would create new LineProcessingWriters
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.
java.io.Writer exposes a protected lock field for synchronization to ensure that output (e.g. line with new line) is written as an atomic unit. I think something like #763 would help here in cases where there might be concurrent things writing to stdout/stderr. I think we can also provide an optimized write(String str, int off, int len) that uses vectorized String#indexOf and bulk char array copy from String to StringBuilder.
...in/groovy/com/palantir/witchcraft/java/logging/gradle/testreport/FormattingTestReporter.java
Outdated
Show resolved
Hide resolved
|
This PR has been automatically marked as stale because it has not been touched in the last 14 days. If you'd like to keep it open, please leave a comment or add the 'long-lived' label, otherwise it'll be closed in 7 days. |
|
Released 2.23.0 |
Before this PR
I saw OOMs on an internal project that I think were contributed to by the code in this class's
writeAllOutput()method. That method holds the output multiple times in memory at once:String contentscontents.split("\n")For the OOM I observed, the failed allocation was in this stacktrace:
After this PR
==COMMIT_MSG==
Reduce memory pressure in FormattingTestReporter
==COMMIT_MSG==
This PR refactors the FormattingTestReporter to hold the contents in memory fewer times. Instead of accumulating all the lines into one
StringWriter stringWriter, we accumulate characters until we find a newline. Then process that line and continue. And instead of writing the line into an intermedia String and then that String into the delegate, we write directly into the delegate.Possible downsides?
TestReportFormattingPluginIntegrationSpecthat verifies the results, but there isn't test coverage for performance, which may have regressed. And this PR doesn't currently include test coverage asserting that large amounts of console output can now be processed even with small heaps (difficult to add tests for)