On Sat, 26 Apr 2025 07:01:46 GMT, Shaojin Wen <s...@openjdk.org> wrote:
>> In the Throwable::printStackTrace method, StringBuilder is created multiple >> times to build String. By sharing StringBuilder to build String, object >> allocation and copying are reduced. >> >> In the scenario without suppressed and ourCause, unused IdentityHashMap is >> not created. >> >> Through these optimizations, the performance of `new >> Exception().printStackTrace()` can be improved by about 10%. > > Shaojin Wen has updated the pull request incrementally with one additional > commit since the last revision: > > fix code style This PR has added a testcase. This patch is safe and does not use Unsafe and SharedSecrets. This optimization is to share StringBuilder as Line Buffer when printStackTrace prints each line. The changes in this PR are actually not many, and the logic has not changed. The goal of the optimization is also very clear, which is to make the program perform better when a large number of exceptions are thrown when an error occurs. This is a very typical scenario. This optimization has taken compatibility into consideration to ensure that the behavior is the same as before. For example, StackTraceElement.toString remains unchanged and calls PrintStreamOrWriter::println(Object) instead of PrintStreamOrWriter::println(String). I hope the discussion can return to this PR and discuss specific technical points instead of philosophy. For example, discuss which line of code is bad, unsafe, not maintainable, and has a better way to write it. ------------- PR Comment: https://git.openjdk.org/jdk/pull/24864#issuecomment-2831929122