10/15/2012

Refactoring, cleaning code, and battling high memory usage!

A little history...

This project started as nothing more than testing some noise-generation algorithms. In fact, even the Visual Studio project was called "TestProject". From there on as new ideas manifested, code began to take form. But my mental image of the code was still that it was just something that I wanted to try out, because it could be cool. So alot of code sprang forth as proof of concepts, with many try & fail iterations on most features. After a while, things settled and I started building further on what I had. The problem was that I never really took the time to clean everything up, refactor, and improve. I'm a huge fan of clean code, and  at some point I tried to reduce cyclic complexities and statements per method. However, about halfway through the code I  realized that when dealing with such computation-heavy code, cleaning up the code created a huge performance overhead. In most everyday projects it's still worth it, but not here. Performance is a key success factor, and it's still too slow for my liking. But alas, further performance optimization has been put on the backburner.

Anyway, without focusing on "clean code" specifically, I've refactored and beautified the code significantly over some time now. The next problem was trying to cope with huge memory usage. It has never been a goal in itself to use as little memory as possible, but I felt at some point the usage was ... Well, a little extreme. I've taken steps to reduce memory usage somewhat, replacing huge array copies with pointers and unsafe code where it seems reasonable. Memory usage is down, but it still chews through quite a bit.

All in all, today I am happier. Not completely content, but happier.

No comments:

Post a Comment