Robin Garner wrote:
GCC Bugzilla Bug 32541
On JikesRVM (and possibly other VMs), dacapo xalan performs lots of
small IO using the default character encoding. OutputStreamWriter
currently buffers characters when converting between character sets, but
bypasses this when not converting. Applying the buffering uniformly
speeds up dacapo xalan by 2x on JikesRVM.
Also, for single character IO, a new char array is allocated per IO
operation. Avoiding this allocation gives a ~5% speedup.
.
.
.
*/
public void write (int ch) throws IOException
{
- write(new char[]{ (char)ch }, 0, 1);
+ // No buffering, no encoding ... just pass through
+ if (encoder == null && outputBuffer == null) {
+ out.write(nullConversion((char)ch));
+ } else {
+ if (outputBuffer != null) {
+ if (outputBuffer.remaining() == 0) {
+ writeConvert(outputBuffer.array(), 0,
BUFFER_SIZE);
+ outputBuffer.clear();
+ }
+ outputBuffer.put((char)ch);
+ } else {
+ writeConvert(new char[]{ (char)ch }, 0, 1);
+ }
+ }
}
Did you read the documentation where it says: "Note that the characters
passed to the write() methods are not buffered."
I don't think we should go around adding buffering to random classes in
the runtime to compensate for problems in an application. The
applications should add buffering themselves when appropriate.
David Daney