The goal of this fix is to solve the lag issue with the newly appearing characters around the player. This is a long-time-known problem in the game that whenever a new character (mostly player-type characters like shaman, ninja etc.. and certain npcs/mobs) appears in the view distance of the player it causes lag/freeze issues, especially on low-spec PCs.
The main problem has been identified in the character loading: Registering motions for the characters took too long, causing screen freeze for the player. Playable characters have more than 200 motions to register unlike the common mobs with ~20 motions. Also some NPCs in the town has high amount of motions.
Some exact numbers of a Sura character loading on a low-spec PC:
Motion load: 1555ms
Mount load: 112ms
Equipment load: 59ms
Others: 1ms
Total: 1727ms ~ 2 seconds
These numbers of course may vary depending on the PC and the equipment/mount of the currently loading character. The preferred load time for a character is under 100ms.
As its found out, the motions has been always loaded for every character, even if the same motion has been loaded before. Therefore the solution for this problem was to implement a cache system for the motions to make the game load one type of motion only once. Also the mostly used characters, mounts, pets and map NPCs now automatically loads in the loading phase before entering a map, causing significantly less time to load them in-game. Other type of characters like mobs, metinstones, etc... may still consume more loading time (no more than before) on the first encounter. Lets say if you first meet with a wild hound it would take some time to cache its motions, but the next instances after the first will take almost no time to create.
Some exact numbers of the same Sura character loading on the same PC with the fix:
Motion load: 0ms
Mount load: 51ms
Equipment load: 72ms
Others: 12ms
Total: 135ms
~90% improved total load time (100% improved motion load time).
Other side effects of the fix:
- The loading screen time may take longer especially on low-spec PCs because of the motion pre-loading.
- The memory usage has been slightly increased in the first few minutes in-game especially if you don't encounter with many players.
- The memory usage has been slightly decreased if you encounter large amount of characters.
Some exact numbers about the memory decrease:
- 1 motion: ~80 Bytes
- 1 player character: ~200 motions -> ~15.625 Bytes
- walking on map 1: ~600 characters -> ~120000 motions -> ~9.375 MBytes
Avg. memory usage difference during tests: ~ -20 MBytes using the new version