# Baking and code generation

### Baking Video Tutorial

{% embed url="<https://www.youtube.com/watch?v=_AqX5UUBHzI&ab_channel=coherence>" %}

### Overview

Out of the box, **coherence** will use *C# Reflection* to sync all the data at runtime. This is a great way to get started but it is very costly performance-wise.

For optimal runtime performance, we need to **create a schema** and perform **code generation** specific to our project.&#x20;

**coherence** offers an automatic way of doing that called **baking.**

Learn more about this in the [How does coherence work](/0.4.14/overview/how-does-coherence-work.md) section.

### Bake schemas

<div align="left"><img src="/files/-MYvSuqFqSO0pjzPThcN" alt=""></div>

Click on `coherence -> Bake Schemas`.

This will go through all `CoherenceSync` components in the project and generate a schema file based on the selected variables, commands and other settings. It will also take into account any `CoherenceArchetype` components.

For every prefab with a `CoherenceSync` object, the baking process will generate a bespoke C# file in the `coherence/baked` folder in the project.&#x20;

Adding that file to the prefab will make that prefab use bespoke generated code instead of C# reflection.

### Activate baked schema on prefab

Once the Schema has been baked, you will be able to activate the baked script in the *Configuration* section of the CoherenceSync component.

![](/files/-Ma4iUSrlZG5lwhMwqm-)

The name of the baked script will be `CoherenceSync[prefabName]`.

![](/files/-MYvU4ONphLnSziyJAO-)

###


---

# 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.coherence.io/0.4.14/get-started/baking-code-generation.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.
