Patch to Throwable and StackTraceElement (reduced CPU usage)
Mike Skells
mike.skells at talk21.com
Wed Oct 12 00:05:13 UTC 2011
Hi David, Patrick,
re explicit StringBuilders
I did try that but the overheads of calling the PrintStreamOrWriter are minimally about the same ( for a StringWriter that I use for the test) but this will clearly depend on the writer that you are using. In my config the end result was slower than what I presented
I did also consider batching multiple lines together but this requires the Throwable to take control of the line endings rather than delegating it to the streams, event though this is a cut across the concerns, but it was slower than what I presented
I also tried making PrintStreamOrWriter extend AbstractStringBuffer and writing to it directly, and then flushing, but again this did not achieve any better results
The majority of the CPu reduction comes from removing the creation of implicit StringBuilders and their resizing
Patrick - this is why you idea doesn't really provide the answer, there is still a StringBuilder created for each line of stack trace printed, and probably a resize as the line is probably > 16 chars, as well as 2 writes for each line
regards
Mike
>________________________________
>From: David Holmes <david.holmes at oracle.com>
>To: Patrick Reinhart <patrick at reini.net>
>Cc: mike.skells at talk21.com; "core-libs-dev at openjdk.java.net" <core-libs-dev at openjdk.java.net>
>Sent: Tuesday, 11 October 2011, 11:16
>Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU usage)
>
>Hi Patrick,
>
>
>On 11/10/2011 3:39 PM, Patrick Reinhart wrote:
>>
>> In my opinion, this could be even written in this ways:
>>
>> for (StackTraceElement traceElement : trace)
>> s.append("\tat ").println(traceElement);
>
>I think you are confusing your streams and your StringBuilders - s is a
>stream.
>
>David
>
>
>>
>> and Similarly for:
>>
>> for (int i = 0; i <= m; i++)
>> s.append(prefix).append("\tat ").println(trace[i]);
>>
>> and the change would be only on one line ;-)
>>
>> Cheers,
>>
>> Patrick "Reini" Reinhart
>>
>>
>>
>> Am 11.10.11 01:12, schrieb David Holmes:
>>> Hi Mike,
>>>
>>> I have one question. In part the existing code tends to use a single
>>> println with multiple string concatenations. Your changes optimize the
>>> string operations by using explicit, rather than implicit
>>> StringBuilders. Did you consider instead/aso using multiple print
>>> statmements top avoid the need for doing the concatenation in the
>>> first place? Eg:
>>>
>>> for (StackTraceElement traceElement : trace)
>>> s.println("\tat " + traceElement);
>>>
>>> becomes
>>>
>>> for (StackTraceElement traceElement : trace) {
>>> s.print("\tat ");
>>> s.println(traceElement);
>>> }
>>>
>>> Similarly for:
>>>
>>> for (int i = 0; i <= m; i++)
>>> s.println(prefix + "\tat " + trace[i]);
>>>
>>>
>>> Cheers,
>>> David Holmes
>>>
>>> On 11/10/2011 8:30 AM, Mike Skells wrote:
>>>> Hi All,
>>>> Last attempt - hopefully
>>>>
>>>> with all 3 files, a patch, test case and results. The patch and
>>>> results are text format to avoid the filters on this list
>>>>
>>>> Hopefully you are not all to irritated with this posting to review it
>>>> :-)
>>>>
>>>> Regards
>>>> Mike
>>>>
>>>>
>>>>> ________________________________
>>>>> From: Mike Skells<mike.skells at talk21.com>
>>>>> To: Core-Libs-Dev<core-libs-dev at openjdk.java.net>
>>>>> Sent: Monday, 10 October 2011, 22:39
>>>>> Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU
>>>>> usage)
>>>>>
>>>>> Hi All,
>>>>> Trying to request a review again with different file types
>>>>>
>>>>> hopefully it will get through the filter
>>>>>
>>>>> Regards
>>>>> Mike
>>>>>
>>>>>
>>>>>
>>>>>> ________________________________
>>>>>> From: Mike Skells<mike.skells at talk21.com>
>>>>>> To: Mike Skells<mike.skells at talk21.com>; Alan
>>>>>> Bateman<Alan.Bateman at oracle.com>
>>>>>> Cc: Core-Libs-Dev<core-libs-dev at openjdk.java.net>
>>>>>> Sent: Monday, 10 October 2011, 9:17
>>>>>> Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU
>>>>>> usage)
>>>>>>
>>>>>>
>>>>>> The patch (.patch) and results (.xlsx) seem to be filtered out.
>>>>>> What is the best format to submit files to avoid list filtering
>>>>>> attachments?
>>>>>>
>>>>>>
>>>>>>
>>>>>>> ________________________________
>>>>>>> From: Mike Skells<mike.skells at talk21.com>
>>>>>>> To: Alan Bateman<Alan.Bateman at oracle.com>
>>>>>>> Cc: Core-Libs-Dev<core-libs-dev at openjdk.java.net>
>>>>>>> Sent: Monday, 10 October 2011, 8:53
>>>>>>> Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU
>>>>>>> usage)
>>>>>>>
>>>>>>> Doh,
>>>>>>> This time with the patches, test code, and CPU usage stats attached
>>>>>>>
>>>>>>> Regard
>>>>>>>
>>>>>>> Mike
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> ________________________________
>>>>>>>> From: Alan Bateman<Alan.Bateman at oracle.com>
>>>>>>>> To: mike.skells at talk21.com
>>>>>>>> Cc: Core-Libs-Dev<core-libs-dev at openjdk.java.net>
>>>>>>>> Sent: Monday, 10 October 2011, 0:15
>>>>>>>> Subject: Re: Patch to Throwable and StackTraceElement (reduced
>>>>>>>> CPU usage)
>>>>>>>>
>>>>>>>> mike.skells at talk21.com wrote:
>>>>>>>>> :
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I include the patch, a micro-benchmark and the results of the
>>>>>>>>> micro-benchmark which show an improvement of 80% throughput (ie
>>>>>>>>> it is almost twice as fast)
>>>>>>>>>
>>>>>>>> Mike - I don't think there is a patch attached to your mail.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>
>
>
>
More information about the core-libs-dev
mailing list