Saturday, December 01, 2007

The Ruby Ceiling

I designed this fun little "civ light" game to build in Ruby on Rails. I even got ImageMagick working for synthesizing the map. Only now that everything's working, I find I've hit a fatal flaw in my otherwise clever plan:

Ruby is really, really, really, really slow.

You don't notice when you're doing something simple, like listing grocery receipts or whatever. But when you tell Rails to create a few thousand entries (tiles on a map), it chokes and essentially dies. I'm sure it would finish eventually, probably. Maybe. But no time this year.

This is something that can be done pretty fast in most situations. I've done something similar in Flash, it takes less than a second. But the combination of Ruby's poor performance and Rail's need to write to a database record by record gums the works up fatally. In order to get around the problem, I would have to generate the map a tiny piece at a time, which would be feasible if what I wanted was a completely crap map... but it's very hard to actually create a realistic-feeling map when you work on it in 5x5 tile chunks!

Maybe an answer will pop into my head (or into my comments), but this is a really irritating flaw. I've heard there's a new version of Ruby out, but trying to get Rails to run properly on a beta language... is not something I care to try.

It's not a flaw I expected to run into.

6 comments:

Patrick said...

Wouldn't be the first time something like this happened to you. :P

Craig Perko said...

No, I don't worry about optimization with a prototype, so I'll usually hit some edge somewhere. But this is a whole new level of slowdown. Ruby makes Flash look like a world-class sprinter.

Olick said...

So wait. Are you putting all these tiles into a database? Or did I read that wrong?

Craig Perko said...

It's impossible NOT to. There's no other choice, because even session variables are done by database.

I expected it to be slow, since it was writing to a database. But I do writing to a database for a living, and I've never had any performance like this.

I don't mean that Rails takes a bit to do this. I mean it takes more than ten minutes.

And I think most of the slowdown is in Ruby, not Rails. The records do require some calculation and, as I've said, I've never seen a database system this slow.

I'm putting it in space, now. I figure, stars don't have to be coherently placed.

Olick said...

Thats dissapointing. Ruby is very usable. I suppose a performance hit should be expected, but not an unreasonable one...

But putting stars in a logical formation could cause some very interesting scenarios! Set the game near a galaxy's central cluster, where industry and trade and diplomacy abound, or place the game near the fringes of a galaxy and encourage martial combat and piracy... I guess those parts depend on the scale of the game.

Craig Perko said...

I was thinking of doing something similar, but that's a whole lot simpler than trying to determine mountain ranges and where deserts are...