performance issue
-----------------
Key: LBCLASSIC-291
URL: http://jira.qos.ch/browse/LBCLASSIC-291
Project: logback-classic
Issue Type: Improvement
Components: Other
Affects Versions: 0.9.29
Reporter: Roman Kosenko
Assignee: Logback dev list
http://logback.qos.ch/manual/encoders.html says:
Below is an excerpt from the LayoutWrappingEncoder class illustrating how
delegation to the wrapped layout instance is done.
package ch.qos.logback.core.encoder;
public class LayoutWrappingEncoder<E> extends EncoderBase<E> {
protected Layout<E> layout;
private Charset charset;
public void doEncode(E event) throws IOException {
String txt = layout.doLayout(event);
outputStream.write(convertToBytes(txt));
outputStream.flush();
}
private byte[] convertToBytes(String s) {
if (charset == null) {
return s.getBytes();
} else {
return s.getBytes(charset);
}
}
}
Let's leave fact that this source is uncompilable...
But in real source of ch.qos.logback.core.encoder.LayoutWrappingEncoder we can
see another code. Method convertToBytes contains line: "return
s.getBytes(charset.name());".
So real variant isn't so fast as one in example - you get the name of your
java.nio.charset.Charset and then String.getBytes make lookup by this name to
get Charset instance again. And this is doing for every log message.
P.S. I know, that String.getBytes(Charset) is available from Java 6 only. But
it released in 2006 and current version is 7. If you want to support very old
version of jre maybe is it better to separate versions like this is doing in
other libraries? Another variant is direct using of CharsetEncoder.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
logback-dev mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-dev