Monday, September 26, 2011

Small efforts, big improvements

Some days ago, following some suggestions of Mark Proctor, I spent just a few hours trying to reduce both the memory footprint and the time requested to create an instance of the WorkingMemory, one of the most used core class of Drools. What I basically did was to lazy initialize all the non-strictly necessary data structures of that class, moving their creation away from the constructor, and rewrite a private method, also invoked during the initialization phase, that used some of those data-structure in a sub-optimal way.

Now I just had time to measure the actual improvements brought by my rework and I must say I was quite positively surprised of the results, especially if compared with the amount of time I spent to implement them. In particular I just tried to create a StatefulSession (that of course uses a WorkingMemory internally) starting from a KnowledgeBase with only one simple rule.

What I found is that my enhancements reduced the memory occupation of that StatefulSession from the initial 11,336 bytes to only 8,610. Even more impressive, the number of instances of StatefulSession I could create in a second, on my machine, increased from the initial 4,668 to an amazing 12,304.

I hope this demonstrates that, even when it seems unlikely, there could be almost always room for important improvements and, at the same time, that not all those improvements comes with a cost, in terms of effort, related with the real benefits they can bring.

4 comments:

  1. Do you have your changes already commited in trunk?

    ReplyDelete
  2. By the way, these are really good news :)

    This sort of micro-benchmarking definitely play an important role when people are looking at adopting a rule engine, because that's the sort of "easy measure" that people will take.

    ReplyDelete
  3. hey leo, how is progress on the range indexing?

    ReplyDelete
  4. Hey Mark,

    Not as good as I would like it to be :(

    I hope to have a bit more time to participate in the list and connect to IRC these days and then we can chat about that.

    Cheers,
    Leo.

    ReplyDelete