hekailiang/squirrel — pull request #11 by jeremystone (2014-01-30 19:07:38+00:00)
Title: performance improvement

While using squirrel framework for a telnet FSM we built at work, it was noticed that CPU was high and throughput low when pushing large quantities or text through it. Profiling indicated the implementation class lookup in SquirrelProvider to be the bottleneck.
I have modified the lookup so that it makes use of the existing registry map to cache looked up implementations.

In a simple unit test included in this pull request, the time for 40000 state transitions reduced from 45 seconds to 2.5 seconds on my machine.

As part of this change it was simpler to extend the registration so that whereas you might have had an interface registered to an interface and then to an implementation (ie just two interfaces), you can now have any number of (different) interfaces registered in a chain on the way to the required implementation. This has been coded as a recursive call with a hashset protecting against cycles. (Creation of this temporary hashset does not appear to make noticeable difference to performance.) Unit tests for this minor extension are included.

Regards, Jeremy Stone