Page 1 of 1

some code performance questions...

Posted: Mon Jan 31, 2011 9:31 am
by rychoo84
hi everyone,
as a non-pro part time noob dev I always try to pay attention to code effectiveness/efficiency/performance etc. I would like to ask you (and I bet there are at least dozens or so pro devs among all ppl involved in l2j project) several questions:

1. What's less "heavy" for the server? let's say we have e.g.:

Code: Select all

 // code 1NpcHtmlMessage msg = new NpcHtmlMessage(0)msg.setHtml(HtmCache.getInstance().getHtm(prefix, path));player.sendPacket(msg); // code 2// subquestion: what about TextBuilder() classStringBuilder sb = new StringBuilder(); sb.append( /* html tags */);NpcHtmlMessage msg = new NpcHtmlMessage(0);msg.setHtml(sb.toString());player.sendPacket(msg); 
2. I'm thinking about adding custom field in characters table which will contain player's amount of deaths during pvp. In order to fill the fields I'm going to put some checks into doDie method inside the L2PcInstance class.

My question is: will it affect a lot the gameplay performance if I update the DB every time the char dies in pvp? (which means every death = DB connection) or would it be better if I store the deaths amount in a variable somewhere inside the L2PcInstance class and update it using threadpoolmanager? (I must take under consideration that some chars may catch DC and handle that occurence too)

I hope you don't mind me asking these questions. Looking forward to get some hints.
Thx in advance!

Re: some code performance questions...

Posted: Mon Jan 31, 2011 10:38 am
by BiggBoss
1)
Htm files are cached into memory (lazy cache just when is used at first time, non lazy cache at server start up). So always will be faster the first option

2) Obviously, store the var into memory and just save on player logs out will be better than a db connection on each die, but i doubt that the database connection on each die would kill your server :roll:

Re: some code performance questions...

Posted: Mon Jan 31, 2011 10:48 am
by rychoo84
allrite, thx for your help BigBoss
Cheers