# Numerous optimizations and dynamic batching

**URL:** <https://forum.castle-engine.io/t/numerous-optimizations-and-dynamic-batching/100>\
**Category:** News\
**Created:** [October 13, 2019, 12:23am UTC](https://forum.castle-engine.io/t/numerous-optimizations-and-dynamic-batching/100 "2019-10-13T00:23:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [October 13, 2019, 12:23am UTC](https://forum.castle-engine.io/t/numerous-optimizations-and-dynamic-batching/100/1 "2019-10-13T00:23:44Z")

</div>

| [![Effects of dynamic batching](https://castle-engine.io/wp/wp-content/uploads/2019/10/batching-200x167.png)](https://castle-engine.io/wp/wp-content/uploads/2019/10/batching.png "Effects of dynamic batching") |

Thanks to many sessions dedicated to optimizing CGE rendering and animation, we have a number of new optimizations (some enabled by default, some experimental — you need to enable them yourself) and new ways to profile your applications.

1. **Various “bottlenecks”** (things that noticeably affect the speed) **are now drastically optimized**. This includes iterating over shapes (it now uses a cache and is instant), transforming frustum (uses a different algorithm that is \> 2x faster), avoiding unnecessary preparing of resources (when everything is prepared), avoiding useless passes when shadow volumes are not used.

2. A **new optimization, enabled by default: frustum culling of the whole scene** ([TCastleScene.SceneFrustumCulling](https://castle-engine.io/apidoc-unstable/html/CastleScene.TCastleScene.html#SceneFrustumCulling)). This works hand-in-hand with the existing per-shape frustum culling, which can be improved when using an octree (if `ssRendering` is in `TCastleScene.Spatial`).

3. A **new experimental powerful optimization called _“dynamic batching”_** is implemented. Multiple X3D shapes (with the same appearance) can be merged into one, and rendered using one “draw call” to OpenGL/OpenGLES. In some applications, this offers incredible speedup — if you have a lot of simple shapes with the same appearance.

4. Another **new experimental powerful optimization is implemented for animations that heavily transform the shapes** (e.g. typical [Spine](https://github.com/castle-engine/castle-engine/wiki/Spine) animations). You can activate it by assigning the global variable [InternalFastTransformUpdate](https://castle-engine.io/apidoc-unstable/html/CastleSceneCore.html#InternalFastTransformUpdate) to true.

5. A new simple way to **observe what is rendered** : just display somewhere (e.g. using TCastleLabel) [SceneManager.Statistics.ToString](https://castle-engine.io/manual_optimization.php#section_scene_manager_stats).

6. A new [FrameProfiler, to observe what is eating time per-frame (e.g. whether the problem is in OnRender or OnUpdate)](https://castle-engine.io/manual_optimization.php#section_frame_profiler).

7. On [Nintendo Switch](https://github.com/castle-engine/castle-engine/wiki/Nintendo-Switch), we are integrated with a cool profiler from Nintendo.

8. To activate risky optimization on Aarch64, you can define `CASTLE_ENGINE_ENABLE_AARCH64_OPTIMIZER` symbol to `true`. We’re working on making them non-risky (we need to reproduce and submit some cases to FPC), at which point we will activate them automatically.

The [manual page about optimizations](https://castle-engine.io/manual_optimization.php) was updated to describe various features mentioned here.
