# Storage Synchronization

## How Deep Lake Datasets are Synchronized with Long-Term Storage

{% hint style="danger" %}
**Using `with` context when updating Deep Lake datasets is critical for achieving rapid write performance.**
{% endhint %}

### BAD PRACTICE - Code without `with` context

By default, any standalone update to a Deep Lake dataset is immediately pushed to the dataset's long-term storage location. Due to the sheer number of discreet write operations, there may be a significant increase in runtime, especially when the data is stored in the cloud. In the example below, an update is pushed to storage for every call to the `.append()` command.

```python
for i in range(10):
    ds.my_tensor.append(i)
```

### Code using `with` context

To reduce the runtime when using Deep Lake, the `with` syntax below significantly improves performance because it only pushes updates to long-term storage after the code block inside the `with` statement has been executed, or when the local cache is full. This significantly reduces the number of discreet write operations, thereby increasing the speed by up to 100X.&#x20;

```python
with ds:
    for i in range(10):
        ds.my_tensor.append(i)
```


---

# 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://docs-v3.activeloop.ai/v3.2.0/how-it-works/storage-synchronization.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.
