Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-612

performance issue

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 0.9.29
    • logback-classic
    • None

    Description

      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.

      Attachments

        Activity

          People

            logback-dev Logback dev list
            kite Roman Kosenko
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: