public RenderedFeatureEncoder newRenderedFeatureEncoder() {
    return new RenderedFeatureEncoder() {
      // This method gets called billions of times when generating the planet, so these optimizations make a big difference:
      // 1) Re-use the same buffer packer to avoid allocating and resizing new byte arrays for every feature.
      private final MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
      // 2) Avoid re-encoding values for identical filled geometries (i.e. ocean) by memoizing the encoded values
      // FeatureRenderer ensures that a separate VectorTileEncoder.Feature is used for each zoom level
      private VectorTile.Feature lastFeature = null;
      private byte[] lastEncodedValue = null;

      @Override
      public SortableFeature apply(RenderedFeature feature) {
        var group = feature.group().orElse(null);
        var thisFeature = feature.vectorTileFeature();
        byte[] encodedValue;
        if (group != null) { // don't bother memoizing if group is present
          encodedValue = encodeValue(thisFeature, group, packer);
        } else if (lastFeature == thisFeature) {
          encodedValue = lastEncodedValue;
        } else { // feature changed, memoize new value
          lastFeature = thisFeature;
          lastEncodedValue = encodedValue = encodeValue(feature.vectorTileFeature(), null, packer);
        }

        return new SortableFeature(encodeKey(feature), encodedValue);
      }

      @Override
      public void close() throws IOException {
        packer.close();
      }
    };
  }
Returns a function for a single thread to use to serialize rendered features.
planetiler-core/src/main/java/com/onthegomap/planetiler/collection/FeatureGroup.java