SAP / cf-java-logging-support

The Java Logging Support for Cloud Foundry supports the creation of structured log messages and the collection of request metrics
Apache License 2.0
77 stars 48 forks source link

Remove StringBuilder in Logback TimestampConverter #90

Closed KarstenSchnitter closed 3 years ago

KarstenSchnitter commented 3 years ago

TimestampConverter in cf-java-logging-support-logback contains the following code:

    @Override
    public String convert(ILoggingEvent event) {
        StringBuilder appendTo = new StringBuilder();
        Instant now = Instant.now();
        long timestamp = now.getEpochSecond() * 1_000_000_000L + now.getNano();
        appendTo.append(timestamp);
        return appendTo.toString();
    }

Creating the StringBuilder is a time consuming implementation for creating a string representation of the long timestamp. This should be changed to a more efficient implementation.

wolches commented 3 years ago

Is this issue actual yet?

KarstenSchnitter commented 3 years ago

@wolches Yes, this is a current open issue. I came across it during a small performance analysis of the library. Since the code is executed for every emitted message, improvements have a larger impact.

KarstenSchnitter commented 3 years ago

Resolved by #97