Commit dex file contents early to free up memory.

This saves a couple GB live heap when writing class-per-file in my extreme
test where we have 1000 classes with 65k string references each.

Bug:
Change-Id: I9e65cacbe7605e009ad9b11f2c2f848ce08f4000
diff --git a/src/main/java/com/android/tools/r8/dex/VirtualFile.java b/src/main/java/com/android/tools/r8/dex/VirtualFile.java
index b80dbd4..eeb5023 100644
--- a/src/main/java/com/android/tools/r8/dex/VirtualFile.java
+++ b/src/main/java/com/android/tools/r8/dex/VirtualFile.java
@@ -245,6 +245,9 @@
           nameToFileMap.put(nameToFileMap.size(), file);
           file.addClass(clazz);
           files.put(clazz, file);
+          // Commit this early, so that we do not keep the transaction state around longer than
+          // needed and clear the underlying sets.
+          file.commitTransaction();
         } else {
           synthetics.add(clazz);
         }
@@ -253,9 +256,9 @@
         for (DexProgramClass inputType : synthetic.getSynthesizedFrom()) {
           VirtualFile file = files.get(inputType);
           file.addClass(synthetic);
+          file.commitTransaction();
         }
       }
-      files.values().forEach(file -> file.commitTransaction());
       return nameToFileMap;
     }
   }