private void mergeAnnotations() {
    new IdMerger<Annotation>(annotationOut) {
      @Override
      TableOfContents.Section getSection(TableOfContents tableOfContents) {
        return tableOfContents.annotations;
      }

      @Override
      Annotation read(Dex.Section in, IndexMap indexMap, int index) {
        return indexMap.adjust(in.readAnnotation());
      }

      @Override
      void updateIndex(int offset, IndexMap indexMap, int oldIndex, int newIndex) {
        indexMap.putAnnotationOffset(offset, annotationOut.getPosition());
      }

      @Override
      void write(Annotation value) {
        value.writeTo(annotationOut);
      }
    }.mergeUnsorted();
  }
minimum number of wasted bytes before it's worthwhile to compact the result
android/android_framework/dex-maker/src/main/java/com/android/dx/merge/DexMerger.java