[r356] Table#_arc_dump Table#_arc_load (in Python)

Started by Blizzard, September 18, 2011, 03:07:42 pm

Previous topic - Next topic

Blizzard

September 18, 2011, 03:07:42 pm Last Edit: September 18, 2011, 03:09:07 pm by Blizzard
Ryex, I updated the Ruby scripts for these methods (_dump, _load, _arc_dump, _arc_load) which turns out to have been a major optimization for Ruby. I noticed that you implemented the Python versions using the same way the Ruby versions used to be implemented. I just wanted to point that out since it would significantly speed up table dumping/loading if you packed the whole data right away with a string instead of doing it for each int and then concatenating with the result string. I noticed that concatenating is a very CPU consuming operation that requires more CPU time the longer the first string is. As I said, I'm just pointing this out as you might wanna optimize this for Python.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

you know... that actually makes a whole lot of sense that it would work like that. will do.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Alright, have fun. xD
You can just take my Ruby code and port it. I think that the * operator works for Pythong strings the same way it works for Ruby strings.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

* Ryex does a quick command line test to see if that's the case

strings are still treated as sequences like lists an tuples so it should
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

That's true, but there is a significant difference. A Ruby string is a C-array that has always a perfect fitting size while a Ruby array allocates more memory than it needs. When the amount is exceeded, more memory is allocated in an array (yet again, more than is required so not every push command requires memory reallocation) while during string concatenation the string memory has to be reallocated every time and this is very time consuming. I noticed this performance issue when I was working on Bitmap2Code a long time ago. It's several times faster to push all strings parts into an array and just use join('') in the end to put the whole string together.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

I think it doubles the amount of current allocated memory every time it needs to resize. 2 -> 4 -> 8 -> 16 -> 32 ,etc, ect.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

ok, I rewrote them the way you did. yet again not tested so...
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Lore

The way it works in Java is that it adds 1, then doubles the current capacity. I am not sure if that is how it is done in Ruby when it exceeds the capacity.
Then again, this is for a StringBuffer class, which is separate from a regular string. Just throwing that out there.
Facebook is like your fridge. You know nothing is in there, but you check every 5 minutes anyways.

Blizzard

Most languages double the capacity. It's an old trick to avoid lots of resizing.

I don't think that there is a StringBuffer/StringBuilder class in Ruby.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.