Issue information

Issue ID
#640
Status
Fixed
Severity
Medium
Started
Hercules Elf Bot
Dec 17, 2007 13:53
Last Post
Hercules Elf Bot
Dec 17, 2007 13:53
Confirmation
N/A

Hercules Elf Bot - Dec 17, 2007 13:53

Originally posted by [b]theultramage[/b]
http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=640

Each object on the mapserver has an unique identifier and a type. These range from players, to mobs, npcs, and even skill units.
There is a single associative array that holds all of these. The measured overall size of this array for an empty server is 10000 with dynamic mobs, 50000 without them.

The problem is, there are periodic actions that run multiple times per second that iterate over this whole array. All of these are type-targeted, meaning many of the entries are skipped over, wasting time.

To combat this, several extra DBMaps have been introduced to work as indexes for the object type: pc_db for players, npc_db for npcs. There are also ones for some other (non-type) attributes and data. These serve as indexes, so that relevant data can be iterated without redundancy.

Problem 1: mobs don't have an index, and mob_ai_sub_lazy clocks 30% cpu time according to the profile (5% cpu load on Poring). This with dynamic mobs on. With it turned off, the thing totally dominates the profile (at 20% constant cpu load). Ridiculous...
Problem 2: skill units don't hav ean index, and skill_unit_timer executes 10 times per second, going over the whole object array again.

So there are 2 possible solutions... either add more DBMaps, or implement a multivalued-key data structure for this thing.
Note: the more maps there are, the more code is needed to maintain these maps. And if an object is stored in multiple maps, there'll be some redundancy going on, plus more code needed to keep these in sync.