> For the complete documentation index, see [llms.txt](https://corvus.gitbook.io/foliage/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://corvus.gitbook.io/foliage/settings/performance.md).

# Performance

Some tips to improve performances of the plugin.

## Performance Settings

This part explains the settings in the `config.yml` file.

### Chunk Cache

```yaml
performance:
  chunk-cache-size: 100
```

* **What it does**: Controls how many chunks of custom block data are kept in memory.
* **Higher values**: Use more RAM but reduce disk access.
* **Lower values**: Save memory but may increase disk I/O.
* **Recommended**: 100 for small servers, 256-512 for larger servers with many players.

### Asynchronous Loading

```yaml
performance:
  async-loading: true
```

* **What it does**: Loads custom block data in the background instead of the main server thread.
* **Enabled**: Reduces impact on server TPS but may cause very slight delays when placing blocks.
* **Disabled**: Blocks appear instantly but can cause server lag during chunk loading.
* **Recommended**: Keep enabled (`true`) for most servers.

### Block Updates Batching

```yaml
performance:
  batch-updates: true
  batch-size: 1000
```

* **What it does**: Groups block updates together to reduce server load.
* **batch-updates**: Enables or disables batch processing.
* **batch-size**: Maximum number of block updates to process at once.
* **Recommended**: Keep enabled with default batch size for most servers. Lower the batch size if you experience lag spikes.

### Save Interval

```yaml
performance:
  save-interval: 300
```

* **What it does**: How often (in seconds) to save custom block data to disk.
* **Higher values**: Less frequent saves, better performance, more risk of data loss on crash.
* **Lower values**: More frequent saves, slightly more resource usage, less data loss risk.
* **Recommended**: 300 seconds (5 minutes) for most servers.

### Dense Forest Handling

```yaml
performance:
  dense-forest:
    emergency-threshold: 8
```

* **What it does**: Controls when the plugin enters emergency mode in densely forested areas.
* **emergency-threshold**: Forest density level (0-10) that triggers emergency optimizations.
* **How it works**: The plugin measures forest density in chunks. When density exceeds this threshold, the plugin uses aggressive optimizations to maintain server performance.
* **Recommended**: Keep at 8 for most servers.

## Troubleshooting Performance Issues

If you experience lag with the Foliage plugin:

1. **Check server TPS** first to confirm the plugin is the cause.
2. **Reduce batch-size** to 500 or lower.
3. **Increase save-interval** to 600 seconds.
4. **Reduce chunk-cache-size** if you're low on RAM.
5. **Lower emergency-threshold** to 7 if you have very dense custom forests.

Remember that the plugin automatically adjusts its processing based on server performance, so these settings serve as guidelines for the automatic system.
