Raised This Month: $ Target: $400
 0% 

[INC] Kvizzle - KeyValues made easy


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 01-15-2014 , 16:38   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #1

Nice job, I love it. I have an idea to fix the issue of "To use Kvizzle, it is important that you only use the Kviz* functions. Using the normal Kv* functions will mess up Kvizzle's functionality.", maybe clone the handle on your side so people can't mess up the functionality of Kvizzle?
Mathias. is offline
F2dk
Junior Member
Join Date: Mar 2009
Old 01-15-2014 , 16:56   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #2

Quote:
Originally Posted by Black-Rabbit View Post
Nice job, I love it. I have an idea to fix the issue of "To use Kvizzle, it is important that you only use the Kviz* functions. Using the normal Kv* functions will mess up Kvizzle's functionality.", maybe clone the handle on your side so people can't mess up the functionality of Kvizzle?
Hi. Thanks for your suggestion.

I am not familiar with CloneHandle, so perhaps you can help me out here. The main problem using Kv-functions on a Kvizzle-handle is that Kvizzle saves the current path of the handle, to optimize subsequent calls to the Kviz-functions. So, using KvGet* is fine, but using KvJump*, KvGoBack, KvRewind, and perhaps KvSet* is a problem.

Will CloneHandle make an actual copy of the KeyValues structure?
F2dk is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-15-2014 , 17:04   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #3

Quote:
Originally Posted by F2dk View Post
Hi. Thanks for your suggestion.

I am not familiar with CloneHandle, so perhaps you can help me out here. The main problem using Kv-functions on a Kvizzle-handle is that Kvizzle saves the current path of the handle, to optimize subsequent calls to the Kviz-functions. So, using KvGet* is fine, but using KvJump*, KvGoBack, KvRewind, and perhaps KvSet* is a problem.

Will CloneHandle make an actual copy of the KeyValues structure?
No. CloneHandle only makes a copy of the handle itself, not the underlying data. A handle isn't truely closed until the original and all copies of it are closed.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
F2dk
Junior Member
Join Date: Mar 2009
Old 01-15-2014 , 17:08   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #4

Quote:
Originally Posted by Powerlord View Post
No. CloneHandle only makes a copy of the handle itself, not the underlying data. A handle isn't truely closed until the original and all copies of it are closed.
Alright, well, then CloneHandle won't solve the problem.

However, it would be possible to make a version of Kvizzle that could be used with the normal Kv-functions. The main problem is that it will be considerably less performant (since it is not allowed to save any state), but that could be useful for single lookups.
F2dk is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-15-2014 , 20:02   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #5

In your example i have to omit the root node, so:

PHP Code:
// don't work
KvizGetStringExact(kvvaluesizeof(value), "Admins:nth-child(10)"); 
PHP Code:
// work
KvizGetStringExact(kvvaluesizeof(value), ":nth-child(10)"); 
Edit:

And i added it to a test plugin.

First of all: It works good. But: It takes four times longer!
__________________

Last edited by dordnung; 01-15-2014 at 20:04.
dordnung is offline
F2dk
Junior Member
Join Date: Mar 2009
Old 01-16-2014 , 01:09   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #6

Quote:
Originally Posted by Popoklopsi View Post
In your example i have to omit the root node, so:
Ah, yes, sorry that this wasn't clear in my example. I have edited it, to include a root. The path is always relative to the root (you should never specify the name of the root). Thanks for clearing this up.

Regarding performance, I have a plugin that reads items_game.txt (2MB file) and loops through all items in it (>2000) and pulls out different kinds of information. Including reading the file, the old Kv way took 181ms, and with Kvizzle it took 192ms.

I also did another test with a much smaller file, where the difference was 1.38ms vs 1.54ms.

If you omit the loading time of the files, the two examples were: 6ms vs 13.2ms, and 0.21ms vs 0.32ms. A more significant difference, but again, we are speaking milliseconds.

It all boils down to this: If you use it in OnPluginStart/OnMapStart, those extra milliseconds really don't matter. It is outweighed by the much cleaner and easier maintainable code. But if you use it in a performance critical section (like OnGameFrame), you should stick to the normal Kv functions.
F2dk is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-16-2014 , 03:20   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #7

Quote:
Originally Posted by F2dk View Post
Ah, yes, sorry that this wasn't clear in my example. I have edited it, to include a root. The path is always relative to the root (you should never specify the name of the root). Thanks for clearing this up.

Regarding performance, I have a plugin that reads items_game.txt (2MB file) and loops through all items in it (>2000) and pulls out different kinds of information. Including reading the file, the old Kv way took 181ms, and with Kvizzle it took 192ms.

I also did another test with a much smaller file, where the difference was 1.38ms vs 1.54ms.

If you omit the loading time of the files, the two examples were: 6ms vs 13.2ms, and 0.21ms vs 0.32ms. A more significant difference, but again, we are speaking milliseconds.

It all boils down to this: If you use it in OnPluginStart/OnMapStart, those extra milliseconds really don't matter. It is outweighed by the much cleaner and easier maintainable code. But if you use it in a performance critical section (like OnGameFrame), you should stick to the normal Kv functions.
Herein lies the problem.
If you are only parsing the data once, you will be storing the data in tries/adt arrays most likely, which will be far superior to constant kv lookups, which is what I normally do. Mabye using this here is appropriate, but the normal kv parsing stuffs is trivial anyway.

Now if you are doing constant kv lookups, it's likely you are using a very simple kv structure, with mabye only one or two subkeys, which is stupid easy to traverse manually. The bottom line here is, if you need to constantly parse kvs, and go deep into them frequenty, you're probably doing it wrong, and need to optimize your code/storage method (change your kv structure, or switch to adt arrays/tries). Using something like this will only slow you down more.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-16-2014 , 05:37   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #8

Only because you don't use keyvalues doesn't mean all people don't use it.

KeyValues are not bad itself, it's the API that is really poor.
And if you want to parse valve's keyvalues, there is nothing to change!

And ADT tries are really not much better than keyvalues
__________________

Last edited by dordnung; 01-16-2014 at 05:51.
dordnung is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-16-2014 , 14:38   Re: [INC] Kvizzle - KeyValues made easy
Reply With Quote #9

Quote:
Originally Posted by Popoklopsi View Post
Only because you don't use keyvalues doesn't mean all people don't use it.

KeyValues are not bad itself, it's the API that is really poor.
And if you want to parse valve's keyvalues, there is nothing to change!

And ADT tries are really not much better than keyvalues
The performance of KeyValues is poor. Hence why SourceMod wrote their own parser constructs for it (SMC).

Edit: Incidentally, keys are stored as a linked list in KeyValues, at least according to the documentation for FindLastSubKey (which SourceMod doesn't support).

As for the API for it, part of the problem with the API is that it was originally an OO API and was ported to SourcePawn. As far as I'm aware, SourcePawn doesn't include any of the changes made to it in the Source 2013 SDK (i.e. FOR_EACH_SUBKEY, GetBool, FindLastSubKey, RecursiveMergeKeyValues, etc...). Or even the KeyValuesCompiler?
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-16-2014 at 15:01.
Powerlord is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode