elastic / ecs-logging-java

https://www.elastic.co/guide/en/ecs-logging/java/current/intro.html
Apache License 2.0
141 stars 75 forks source link

Give StringBuilder an initial capacity #149

Closed echatman closed 2 years ago

echatman commented 2 years ago

https://github.com/elastic/ecs-logging-java/blob/c91dd98b2223d008a32d60f4172375eaffba84d3/logback-ecs-encoder/src/main/java/co/elastic/logging/logback/EcsEncoder.java#L98

The default StringBuilder constructor starts with a capacity of 16, which is always going to be too low. Playing around with the encoder, the shortest message I could generate was 142 characters long: {"@timestamp":"2021-10-13T23:04:17.024Z", "log.level": "INFO", "message":"", "ecs.version": "1.2.0","process.thread.name":"","log.logger":""} and of course most messages are going to be much bigger than that

felixbarny commented 2 years ago

Good idea. What initial size would you propose? Maybe 256? Do you want to create a PR for that?