RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

deserialization optimization

noobie

Wanderer
deserialization optimization

I am an old runuo guy, it has been almost two year that I havent looked runuo scripts.
today, I had a chance to overlook some core scripts..

While loading the world, there is an issue with hashtables..

A hashtable's size is never the same as the count of objects in itself.
Approximately, the max number of objects would be the half of the size..

(I checked MSDN for more info, the most efficient ratio is 0.72 which is default)

Consider the following situation:
-lets say you created a hashtable with the initial capacity 100.
-insert 72 items
-if you insert one more item, what will happen?

If you try to insert one more item, before it's hashed and located, the following occurs:
-hashtable is expanded (almost doubled)
-each item in hashtable is rehashed and relocated..

So, obviously this is an important overhead..

To resolve the problem, the initial capacity of the hashtables should be double of the item/mobile count, so that loading factor would be 0.5

The less loading factor is , the more faster loading will be..(less collision, faster lookup)
0.5 is fine almost anytime. Also it gives some flexibility for runtime.

It is possible to choose different loading factors for items and mobiles. The number of mobiles could be considered as more stable than the number of items, so you can choose a loading factor like 0.6 . It is really a trade-off between speed and memory, decision is up to you..

the more info about hashtables

Anyway, the current implementation should be changed whatever loading factor you choose..

I hope RunUO team consider my suggestion :)
 

noobie

Wanderer
that would be probably generics. you dont need to downcast objects anymore.
however, that doesnt mean hashtables will not be used. I guess he is planning to change it to generic hashtable. (thats just a guess) You will still need to make needed change for deserialization..

I do not know much what is coming with 2.0, only a few headlines..but chaning it from hastables to something else entirely different might take some serious time..
 

noobie

Wanderer
hmzzz, Dictionary is nothing but the strongly-typed version of hashtable. However, usage of initial capacity seems to be changed. But since most of the generics is almost the same except strongly-typed issue, the internal implementation would be same. (there will be a loading factor internally)

Dictionary is expanded when more items will be loaded. Maybe it wont happen in the loading stage since item count is same as the given parameter, but it will happen in runtime ( i guess it is worse :))

anyway, I think it is more appropriate to assign some higher value to initial capacity for runtime issues, even if it is a Dictionary class..

btw, there are some blogs, you might wanna look around:
from one of the my favourite guys:
Brad Abrams
and another two as a reply to his blog:
Justin Rogers
another Justin Rogers

I guess it wont be a real problem to change it from HashTable to Dictionary..

this was not a big issue, since it only effects loading stage but not runtime. but i just wanted you-guys to be aware of it :)
 

noobie

Wanderer
i am lost.

why is Phantom's all messages are deleted in my various threads??

the funny thing is only the messages that I didnt quote are deleted.lol
 

Phantom

Knight
noobie said:
i am lost.

why is Phantom's all messages are deleted in my various threads??

the funny thing is only the messages that I didnt quote are deleted.lol

I removed them the reason for doing so is not important.
 
Top