> For the complete documentation index, see [llms.txt](https://docs.coherence.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherence.io/0.4.14/get-started/baking-code-generation.md).

# 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="https://3643360286-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd0ZPEK7vE9nkE0b7G%2F-MYvSkLFiquVG19Wn1e7%2F-MYvSuqFqSO0pjzPThcN%2Fimage.png?alt=media&amp;token=3981990e-d141-4cbe-bcfe-092a0e9c82a0" 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.

![](https://3643360286-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd0ZPEK7vE9nkE0b7G%2F-Ma3wvuvMY7zHD0EN-IT%2F-Ma4iUSrlZG5lwhMwqm-%2Fbaked.png?alt=media\&token=265e6ad0-11e8-4010-bc3b-519d80ad4f5f)

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

![](https://3643360286-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd0ZPEK7vE9nkE0b7G%2F-MYvSkLFiquVG19Wn1e7%2F-MYvU4ONphLnSziyJAO-%2Fimage.png?alt=media\&token=4a0af6e2-ebe9-4371-87d7-c20d03a3d24e)

###
