Guide

How to Generate an AOT Cache for a Hytale Server

How to Generate an AOT Cache for a Hytale Server

Generating an Ahead-Of-Time (AOT) cache for your Hytale server is a critical step to significantly reduce server startup times, ensuring a smoother and faster launch experience for both administrators and players. This cache provides pre-optimized code, allowing the server to bypass the initial Just-In-Time (JIT) compilation phase that typically slows down Java applications.

Understanding the Hytale AOT Cache

The Hytale server, being a Java-based application, normally relies on the Java Virtual Machine’s (JVM) JIT compiler to optimize code during runtime. This process, while beneficial for long-running applications, introduces a “warm-up” period during server startup as the JVM compiles and optimizes frequently used code paths. The AOT cache, typically named HytaleServer.aot, circumvents this by providing pre-compiled, optimized code. When the server launches, it can immediately utilize this cache, drastically cutting down the time it takes to become fully operational.

The server usually ships with a pre-trained HytaleServer.aot file. If one doesn’t exist or is outdated, the server can generate or update it during its first run with the appropriate JVM argument. This file is generally located within the server’s directory, often inside a dedicated .cache/ folder for optimized files.

Step-by-Step Guide to Generating and Utilizing an AOT Cache

The process of generating or utilizing an AOT cache primarily involves launching your Hytale server with a specific JVM argument. Follow these steps to ensure your server benefits from this optimization.

Step 1: Install Java 25

Hytale servers are specifically designed to run on Java 25. It is highly recommended to use a stable distribution like Eclipse Temurin from Adoptium for optimal compatibility and performance. If you haven’t already, download and install the appropriate Java 25 Development Kit (JDK) for your operating system.

  • Verification: After installation, open your command line interface (CLI) or terminal and type java --version. Confirm that the output indicates Java version 25.

Step 2: Download Hytale Server Files

Ensure you have the necessary Hytale server files. This includes the main server executable, HytaleServer.jar, and the game assets package, Assets.zip. These files can typically be obtained by copying them from your Hytale launcher installation or by using the official Hytale Downloader CLI tool.

  • Place both HytaleServer.jar and Assets.zip in a dedicated folder on your server machine. This will be your server’s root directory.

Step 3: Navigate to Your Server Directory

Open your command line interface (CLI) or terminal. Use the cd command to navigate to the directory where you placed your HytaleServer.jar and Assets.zip files.

Example (Windows):

cd C:\HytaleServer

Example (Linux/macOS):

cd /home/user/hytale_server

Step 4: Launch with AOT Cache Argument

Now, execute the command to start your Hytale server, incorporating the AOT cache argument. The -XX:AOTCache=HytaleServer.aot flag tells the JVM to use or create the AOT cache file named HytaleServer.aot.

Basic Launch Command:

java -XX:AOTCache=HytaleServer.aot -jar HytaleServer.jar --assets Assets.zip

Recommended Production Launch Command:

For production environments, it’s highly advisable to include memory allocation and garbage collector flags for improved stability and performance. Replace 6G with the appropriate memory allocation for your server (e.g., 8G, 12G).

java -Xms6G -Xmx6G -XX:+UseG1GC -XX:AOTCache=HytaleServer.aot -jar HytaleServer.jar --assets Assets.zip --backup --backup-frequency 60
  • -Xms6G: Sets the initial Java heap size to 6 Gigabytes.
  • -Xmx6G: Sets the maximum Java heap size to 6 Gigabytes. Matching -Xms and -Xmx prevents the JVM from resizing its memory pool during operation, which can cause performance hiccups.
  • -XX:+UseG1GC: Enables the G1 Garbage Collector, which is generally recommended for servers with large memory heaps.
  • --backup: Enables automatic server backups.
  • --backup-frequency 60: Sets the backup frequency to 60 minutes.

Step 5: First Run Behavior

During the very first launch with the AOT cache argument, or if the existing cache is outdated, the server may take a bit longer than subsequent launches. This is because it’s actively building or integrating with the cache. You might see messages related to AOT compilation in the server console. Once this initial process is complete, subsequent server launches will be significantly faster, leveraging the pre-compiled code.

Tips for AOT Cache and Server Optimization

Beyond just generating the AOT cache, several other practices can further optimize your Hytale server’s performance.

Memory Allocation

As mentioned in Step 4, setting both -Xms (initial memory) and -Xmx (maximum memory) to the same value is crucial. This prevents the JVM from dynamically resizing its memory pool, which can introduce pauses. However, do not allocate all available system RAM to Hytale. Always reserve at least 2-4 GB for the operating system and other essential background processes to maintain system stability.

Garbage Collector

Using the G1 Garbage Collector (-XX:+UseG1GC) is recommended for servers with substantial memory allocations. It’s designed to handle large heaps more efficiently than older garbage collectors, reducing pause times.

Start Scripts

To simplify server launches and ensure all necessary arguments are consistently applied, create a start script. This is a simple text file with a .bat extension for Windows or a .sh extension for Linux/macOS, containing your full launch command. This allows you to start your server with a single click or command.

View Distance Optimization

The MaxViewRadius setting in your config.json file dictates how many chunks are loaded around players. The default of 32 chunks is very demanding. Reducing this to a more manageable 12 chunks (equivalent to 384 blocks) can significantly improve server performance, as view distance scales quadratically with server workload and resource consumption (CPU, RAM, network bandwidth).

Hardware Considerations

For optimal Hytale server performance, prioritize CPU clock speed over core count. The Hytale server primarily utilizes 2-4 threads efficiently, so a CPU with high single-core performance will generally outperform one with many slower cores. Additionally, an NVMe Solid State Drive (SSD) is highly recommended. Its superior input/output (I/O) speeds prevent stutters during chunk loading, world saves, and asset access.

World Pre-generation

Pre-generating terrain around your spawn areas and frequently traveled routes can eliminate lag spikes caused by the server generating new chunks on demand. Tools or server commands for world pre-generation, once available, should be utilized to ensure a smooth player experience.

Common Mistakes to Avoid

  • Not Using the AOT Cache: Failing to include the -XX:AOTCache=HytaleServer.aot flag will result in slower startup times, negating the primary benefit of this optimization.
  • Incorrect Java Version: Hytale servers require Java 25. Using an older or incompatible Java version can lead to server startup failures or stability issues.
  • Allocating All RAM: Giving the entire system’s available RAM to the Hytale server is detrimental. It leaves insufficient memory for the operating system and other critical processes, leading to system instability and overall poor performance.
  • Ignoring View Distance: Keeping the default high MaxViewRadius without sufficient hardware resources will drastically increase RAM usage, CPU load, and network traffic, causing significant lag for players.
  • Not Opening UDP Port 5520: Hytale uses the QUIC protocol over UDP port 5520 for client-server communication. If this port is not open in your firewall or router, players will be unable to connect to your server.
  • Stale AOT Cache: While not officially documented as a common issue, some users have reported that clearing the HytaleServer.aot file resolved server connection issues. If you encounter inexplicable problems, especially after server updates, consider deleting the cache file and allowing the server to regenerate it on the next launch.

By following this guide, you can ensure your Hytale server starts quickly and runs efficiently, providing a better experience for all players.