Index: branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/AsyncBuffer.cs
===================================================================
--- branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/AsyncBuffer.cs	(revision 6211)
+++ branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/AsyncBuffer.cs	(revision 6211)
@@ -0,0 +1,104 @@
+﻿using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+
+namespace HeuristicLab.Persistence.Default.Xml {
+
+  public class AsyncBuffer<T> : IDisposable, IEnumerable<T>, IEnumerable {
+
+    private IEnumerator<T> it;
+
+    private Queue<T> queue;
+    private object queueLock;
+    private AutoResetEvent elementAdded;
+
+    private Thread thread;
+    private ManualResetEventSlim done;
+
+    private Exception exception;
+
+    private class LockIndicator {
+      public bool HasLock;
+      public LockIndicator() { HasLock = false; }
+    }
+
+    public AsyncBuffer(IEnumerable<T> source) {
+      it = source.GetEnumerator();
+      queue = new Queue<T>();
+      queueLock = new object();
+      elementAdded = new AutoResetEvent(false);
+      thread = new Thread(Run);
+      done = new ManualResetEventSlim(false);
+      thread.Start();
+    }
+
+    private void Run() {
+      try {
+        while (it.MoveNext()) {
+          T value = it.Current;
+          lock (queueLock) {
+            queue.Enqueue(value);
+            elementAdded.Set();
+          }
+        }
+      } catch (Exception x) {
+        exception = x;
+      }
+      done.Set();
+    }
+
+    #region IEnumerable<T> Members
+    public IEnumerator<T> GetEnumerator() {
+      LockIndicator li = new LockIndicator();
+      try {
+        return RealGetEnumerator(li);
+      } catch {
+        if (li.HasLock)
+          Monitor.Exit(queueLock);
+        throw;
+      }
+    }
+
+    private IEnumerator<T> RealGetEnumerator(LockIndicator li) {
+      Monitor.Enter(queueLock, ref li.HasLock);
+      while (!done.IsSet || queue.Any()) {
+        while (!queue.Any() && !done.IsSet) {
+          li.HasLock = false;
+          Monitor.Exit(queueLock);
+          AutoResetEvent.WaitAny(new WaitHandle[] { done.WaitHandle, elementAdded });
+          Monitor.Enter(queueLock, ref li.HasLock);
+        }
+        if (queue.Any()) {
+          T element = queue.Peek();
+          li.HasLock = false;
+          Monitor.Exit(queueLock);
+          yield return element;
+          Monitor.Enter(queueLock, ref li.HasLock);
+          queue.Dequeue();
+        }
+      }
+      li.HasLock = false;
+      Monitor.Exit(queueLock);
+      if (exception != null)
+        throw exception;
+    }
+    #endregion
+
+    #region IEnumerable Members
+    IEnumerator IEnumerable.GetEnumerator() {
+      return GetEnumerator();
+    }
+    #endregion
+
+    #region IDisposable Members
+    public void Dispose() {
+      if (elementAdded != null)
+        elementAdded.Dispose();
+      if (done != null)
+        done.Dispose();
+    }
+    #endregion
+  }
+}
Index: branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
===================================================================
--- branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs	(revision 6206)
+++ branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs	(revision 6211)
@@ -257,6 +257,5 @@
           {"typeName", lastTypeToken.TypeName },
           {"serializer", lastTypeToken.Serializer }});
-      }
-      finally {
+      } finally {
         lastTypeToken = null;
       }
@@ -333,11 +332,10 @@
             zipStream.PutNextEntry(new ZipEntry("data.xml") { DateTime = DateTime.MinValue });
             StreamWriter writer = new StreamWriter(zipStream);
-            foreach (ISerializationToken token in serializer) {
-              string line = generator.Format(token);
-              writer.Write(line);
+            foreach (ISerializationToken token in new AsyncBuffer<ISerializationToken>(serializer)) {
+              writer.Write(generator.Format(token));
             }
             writer.Flush();
             zipStream.PutNextEntry(new ZipEntry("typecache.xml") { DateTime = DateTime.MinValue });
-            foreach (string line in generator.Format(serializer.TypeCache)) {
+            foreach (string line in new AsyncBuffer<string>(generator.Format(serializer.TypeCache))) {
               writer.Write(line);
             }
@@ -368,6 +366,5 @@
         File.Copy(tempfile, filename, true);
         File.Delete(tempfile);
-      }
-      catch (Exception) {
+      } catch (Exception) {
         Logger.Warn("Exception caught, no data has been written.");
         throw;
@@ -438,5 +435,5 @@
         serializer.InterleaveTypeInformation = true;
         XmlGenerator generator = new XmlGenerator();
-        foreach (ISerializationToken token in serializer) {
+        foreach (ISerializationToken token in new AsyncBuffer<ISerializationToken>(serializer)) {
           string line = generator.Format(token);
           writer.Write(line);
Index: branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
===================================================================
--- branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs	(revision 6206)
+++ branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs	(revision 6211)
@@ -75,6 +75,5 @@
         try {
           iterator = handlers[reader.Name].Invoke();
-        }
-        catch (KeyNotFoundException) {
+        } catch (KeyNotFoundException) {
           throw new PersistenceException(String.Format(
             "Invalid XML tag \"{0}\" in persistence file.",
@@ -176,9 +175,7 @@
         }
         return typeCache;
-      }
-      catch (PersistenceException) {
+      } catch (PersistenceException) {
         throw;
-      }
-      catch (Exception e) {
+      } catch (Exception e) {
         throw new PersistenceException("Unexpected exception during type cache parsing.", e);
       }
@@ -196,6 +193,5 @@
           return Deserialize(file);
         }
-      }
-      finally {
+      } finally {
         TimeSpan end = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
         Tracing.Logger.Info(string.Format(
@@ -226,11 +222,9 @@
           XmlParser parser = new XmlParser(reader);
           Deserializer deserializer = new Deserializer(new TypeMapping[] { });
-          return deserializer.Deserialize(parser);
-        }
-      }
-      catch (PersistenceException) {
+          return deserializer.Deserialize(new AsyncBuffer<ISerializationToken>(parser));
+        }
+      } catch (PersistenceException) {
         throw;
-      }
-      catch (Exception x) {
+      } catch (Exception x) {
         throw new PersistenceException("Unexpected exception during deserialization", x);
       }
@@ -258,12 +252,10 @@
         XmlParser parser = new XmlParser(
           new StreamReader(zipFile.GetInputStream(data)));
-        object result = deSerializer.Deserialize(parser);
+        object result = deSerializer.Deserialize(new AsyncBuffer<ISerializationToken>(parser));
         zipFile.Close();
         return result;
-      }
-      catch (PersistenceException) {
+      } catch (PersistenceException) {
         throw;
-      }
-      catch (Exception e) {
+      } catch (Exception e) {
         throw new PersistenceException("Unexpected exception during deserialization", e);
       }
