public static TsvSerializer newThreadLocalSerializer() {
    // CsvMapper is not entirely thread safe, and can end up with a BufferRecycler memory leak when writeValueAsString
    // is called billions of times from multiple threads, so we generate a new instance per serializing thread
    ObjectWriter writer = new CsvMapper().writer(SCHEMA);
    return (tileCoord, archivedBytes, layerStats) -> {
      int hilbert = tileCoord.hilbertEncoded();
      List<String> result = new ArrayList<>(layerStats.size());
      for (var layer : layerStats) {
        result.add(writer.writeValueAsString(new OutputRow(
          tileCoord.z(),
          tileCoord.x(),
          tileCoord.y(),
          hilbert,
          archivedBytes,
          layer.layer,
          layer.layerBytes,
          layer.layerFeatures,
          layer.layerGeometries,
          layer.layerAttrBytes,
          layer.layerAttrKeys,
          layer.layerAttrValues
        )));
      }
      return result;
    };
  }
Returns a {@link TsvSerializer} that can be used by a single thread to convert to CSV rows.
planetiler-core/src/main/java/com/onthegomap/planetiler/util/TileSizeStats.java