title: What is the fastest way to persist large complex data objects in Powershell for a short term period?
body: <p>Case in point - I have a build which invokes a lot of REST API calls and processes the results. I would like to split the monolithic step that does all that into 3 steps:</p>
  <ol>
  <li>initial data acquisition - gets data from REST Api. Plain objects, no reference loops or duplicate references</li>
  <li>data massaging - enriches the data from (1) with all kinds of useful information. May result in duplicate references (the same object is referenced from multiple places) or reference loops.</li>
  <li>data processing</li>
  </ol>
  <p>The catch is that there is a lot of data and converting it to json takes too much time to my taste. I did not check the <code>Export-CliXml</code> function, but I think it would be slow too.</p>
  <p>If I wrote the code in C# I would use some kind of binary serialization, which should be sophisticated enough to handle reference loops and duplicate references.</p>
  <p>Please, note that serialization would write to the build staging directory and would be deserialized almost immediately as soon as the next step runs.</p>
  <p>I wonder what are my options in Powershell?</p>
  <p><strong>EDIT 1</strong></p>
  <p>I would like to clarify what do I mean by steps. This is a build running on a CI build server. Each step runs in a separate shell and is reported individually on the build page. There is no memory sharing between the steps. The only way to communicate between the steps is either through build variables or file system. Of course, using databases is also possible, but it is an overkill.</p>
  <p>Build variables are set using certain API and are exposed to the subsequent steps as environment variables. As such they are quite limited in length.</p>
  <p>So I am talking about communicating through the file system. I am sacrificing performance here for the sake of build granularity - instead of having one monolithic step I want to have 3 smaller steps. This way the build is more transparent and communicates clearly what it is doing. But I have to temporarily persist payloads between steps. If it is possible to minimize the overhead, then the benefits worth it. If the performance is going to degrade significantly, then I will keep the monolithic step.</p>