Monkey Blog Stuff

Monkey Archive Forums/Monkey Tutorials/Monkey Blog Stuff

muddy_shoes(Posted 2012) [#1]
I'm not sure if this really fits with what simonh wanted from this forum, but it seems to be a good match for what I'm doing and it's pretty quiet in here. Feel free to move or delete this if you wish.

Anyway, I'm starting to write some blog posts about Monkey. Tips, lessons learned, that sort of thing. They might be of interest to people here (and if not then I've no idea who else would care!) so I thought I'd start dropping links in here.

So, here's one on how performance varies across targets: http://pointlessdiversions.blogspot.co.nz/2012/03/monkey-tip-relative-target-performance.html

Feel free to comment here or on the blog if you think I'm getting something wrong. Or right.


c.k.(Posted 2012) [#2]
Good stuff, muddy! Keep it up!


muddy_shoes(Posted 2012) [#3]
Thanks.

Coincidentally, I've just put up a new post about box classes: http://pointlessdiversions.blogspot.co.nz/2012/03/monkey-tip-be-careful-around-unboxing.html


Why0Why(Posted 2012) [#4]
Thanks for posting. Thorough and well written.


muddy_shoes(Posted 2012) [#5]
Additions:

http://pointlessdiversions.blogspot.co.nz/2012/04/monkey-tips-default-types-and-implicit.html

http://pointlessdiversions.blogspot.co.nz/2012/05/1d-vs-2d-arrays-performance-reality.html


therevills(Posted 2012) [#6]
These are great to read muddy shoes, keep it up :)

Re: monkey-tips-default-types-and-implicit.html

My write up would just be: Just use "Strict" mode - The End ;)


Re: 1d-vs-2d-arrays-performance-reality.html

It would be good to see your testing code.


muddy_shoes(Posted 2012) [#7]
My write up would just be: Just use "Strict" mode - The End ;)


Well that is the take home. The thing is that if you don't understand the issues with not using Strict it just seems like it's an annoyance.

It would be good to see your testing code.


I'll sort something out with attaching code to relevant posts at some point. Most of these tests aren't written as code for public consumption though. Tidying things up and making them into neat packages for posting is an additional time burden. If someone created a test that showed something very different I'd be happy to revisit the code to see what's up, of course.

I'll probably write a post about performance testing for Monkey in general and post some template code for that.


DruggedBunny(Posted 2012) [#8]
I'm with therevills -- these are really good reads, thanks.


muddy_shoes(Posted 2012) [#9]
This post isn't really about Monkey, but it's about something written in Monkey and there's code linked so it might be of interest: http://pointlessdiversions.blogspot.co.nz/2012/05/tetris-in-how-long.html


NoOdle(Posted 2012) [#10]
good read. And of course, challenge accepted!! Will have a bash at Tetris later after I've sorted out a few errands in town. I'll let you know how I fair... 2 hr is going to be a challenge, I tend to slip off into dream land for at least 15 mins every hour and spend far too long playing, err i mean 'testing' my code!


wiebow(Posted 2012) [#11]
The last post is fun! Thanks for your insights :)


muddy_shoes(Posted 2012) [#12]
Got around to writing something again:

http://pointlessdiversions.blogspot.co.nz/2012/06/monkeys-garbage-collection-on-ios.html

Just a cautionary note about garbage collection behaviour on iOS.


therevills(Posted 2012) [#13]
Another great read Muddy :)

On the topic of GC, you need to be careful with Android too... try not to create any new objects during your game and preallocate all your game objects beforehand (note: using the default Monkey List when you iterate over it you will create a new object!)


muddy_shoes(Posted 2012) [#14]
Sure, GC can be an issue on any platform that implements it. The problem with iOS is that the default behaviour will be made worse by taking your suggestion of pre-allocating. Further, even if you have zero allocations the iOS GC will probably still be doing pretty much the same amount of work as marking the objects generally takes much longer than sweeping.

Zero allocation is a nice thing to have but not always practical to achieve. If you're down to worrying about list iterators then you'd have to be almost done though as they're both small and unlikely to be numerous. Most GCs don't trigger until a certain amount of allocation has taken place and a few list iterators per frame certainly aren't at the top of my list of trouble makers.


therevills(Posted 2012) [#15]
On how the Android GC works, every time you create a "new" object you are saying "Hey GC, go for collect for me and kill me game!".

With iOS I never had an issue with the GC, but all I did was a simple card game :D


Why0Why(Posted 2012) [#16]
Excellent. Thorough and well written, as usual. Thanks for taking the time.


muddy_shoes(Posted 2012) [#17]
On how the Android GC works, every time you create a "new" object you are saying "Hey GC, go for collect for me and kill me game!".


Any given allocation might result in a collection event but GCs aren't generally written so naively that they try to collect as soon as you allocate an object. There's obviously no benefit in attempting to recover memory based on the demand of a single allocation so they don't.

Here's the Android GC activity using a version of the test from my post that allocates and releases 20,000 objects at a time:



Yes, if you've got some internal method call that uses a list iterator and gets called dozens or hundreds of times a frame then it'll be adding to your GC burden. On the other hand I think it's a little misleading/over-simplified to talk about using them at all as a big no-no or that any object allocation will result in the GC monster stomping through your living room.

Obviously, if you want absolutely no GC at all guaranteed over long play sessions then you're going to have to remove all allocations. Unfortunately the nature of mobile OSes means that other processes will come along and mess up your timing anyway so expending a lot of effort removing all allocations might not gain you much in terms of user experience on Android (at least on 2.3+ where the GC is pretty fast but then anything less is rapidly becoming legacy). If you're targeting XBox or PS Vita then there's probably more reason to put the time into avoiding any collection costs.


muddy_shoes(Posted 2012) [#18]
Having said that I had a bit of a think and decided there's no reason not to have the best of both worlds. I've altered the monkey parser to call a Discard method on the ObjectEnumerator after it creates a While loop for the Eachin. A simple cache array for enumerators in the collection and you have no GC issues and no need to lose the syntactic sugar.


muddy_shoes(Posted 2013) [#19]
Time flies... a year since I added to this? Wow.

Anyway. A recent Twitter conversation with Raph and head-desk debugging experience led me to revisit the topic of autoboxing and add a further warning: http://pointlessdiversions.blogspot.co.nz/2013/07/boxes-sneaky-buggers.html


Raph(Posted 2013) [#20]
Aha, now I can connect you to the Twitter handle! :)


AdamRedwoods(Posted 2013) [#21]
nice blog post.