# Persistent and Transient Data Structures

Immutable data structures are also sometimes referred to as **persistent data structures**, since its values persist for its lifetime. Immutable.js provides the option for **transient data structures**, which is a mutable version of a persistent data structure during a transformation stage and returning a new immutable version upon completion. This is one approach to solving the performance issues we encountered earlier. Let's revisit the immutable case outlined in the performance example, but using a transient data structure this time:

```javascript
import * as Immutable from 'immutable';

let list = Immutable.List();

list = list.withMutations(mutableList => {
  let val = "";

  return Immutable.Range(0, 1000000)
    .forEach(() => {
      val += "concatenation";
      mutableList.push(val);
  });
});

console.log(list.size); // writes 1000000
list.push('');
console.log(list.size); // writes 1000000
```

As we can see in [this performance test](http://jsperf.com/immutable-js-data-structure-perf2/2), the transient list builder was still a lot slower than the fully mutable version, but much faster than the fully immutable version. Also, if you pass the mutable array to `Immutable.List` or `Immutable.fromJS`, you'll find the transient version closes the performance gap. The test also shows how slow `Object.freeze` can be compared to the other 3.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rangle-io.gitbook.io/react-training/index-3/index-1/persistent_and_transient_data_structures.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
