finite state machine performance info

Hi All Yesterday I started playing with Boost State Chart library implementing state machines for my applications. Each time I am moving into a new state I noticed that a new state is created; this means that the constructor of the boost::statechart::state class is called each time ( and the destructor for the state that I am leaving ). I would like to fasten up the whole process; let's say that I would like to avoid the creation/destruction of the class each time using object already allocated in memory that are deleted only at the exit of the application. Is this a good way in your opinion ? I saw that there is an allocator template argument but at the state where I am now I would lilke to not spend time in doing a new allocator for that: do you know if there already in place something that I can reuse for my purpose? Thanks CS

Conoscenza Silente wrote:
I would like to fasten up the whole process; let's say that I would like to avoid the creation/destruction of the class each time using object already allocated in memory that are deleted only at the exit of the application. Is this a good way in your opinion ?
So when you profile your entire application, how much time is being spent in boost's state library?

Whell I did a small test application to test the usage of
boost::pool_allocator and boost::fast_pool_allocator. My application will
possibly do a lot of transition from a state to another.
I found that it is better to use state chart classes without allocator.
In the code below tese are the results:
- Without allocator 5.7 sec
- with boost::pool_allocator 10.7 sec
- with boost::fast_pool_allocator 8.7 sec
Next action could be
- test with another allocator
- try the asynchronous version
Any suggestion?
#include
{};
struct event_1_2 : event< event_1_2 //, boost::fast_pool_allocator< event_1_2 >
{}; struct event_2_3 : event< event_2_3 //, boost::fast_pool_allocator< event_2_3 > {}; struct event_3_4 : event< event_3_4 //, boost::fast_pool_allocator< event_3_4 > {}; struct event_4_1 : event< event_4_1 //, boost::fast_pool_allocator< event_4_1 > {};
struct state_1
: simple_state< state_1, main_machine >
{
typedef transition< event_1_2, state_2 > reactions;
};
struct state_2
: simple_state< state_2, main_machine >
{
typedef transition< event_2_3, state_3 > reactions;
};
struct state_3
: simple_state< state_3, main_machine >
{
//typedef transition< event_3_4, state_4 > arc; // it doesn't work
typedef transition< event_3_4, state_4 > reactions;
//state_3(){std::cout<<"3";}
//~state_3(){std::cout<<"~3";}
};
struct state_4
: simple_state< state_4, main_machine >
{
typedef transition< event_4_1, state_1 > reactions;
};
void main(){
main_machine fsm;
fsm.initiate();
{
boost::progress_timer t; // count the time elapsed
// before distruction: not very precise
// for expected big differences
for( int i = 0; i < 1000000; i ++ ){
fsm.process_event( event_1_2() );
fsm.process_event( event_2_3() );
fsm.process_event( event_3_4() );
fsm.process_event( event_4_1() );
}
}
}
On Thu, Nov 26, 2009 at 4:57 PM, Eric J. Holtman
Conoscenza Silente wrote:
I would like to fasten up the whole process; let's say that I would like to avoid the creation/destruction of the class each time using object already allocated in memory that are deleted only at the exit of the application. Is this a good way in your opinion ?
So when you profile your entire application, how much time is being spent in boost's state library? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Conoscenza Silente wrote:
Whell I did a small test application to test the usage of boost::pool_allocator and boost::fast_pool_allocator. My application will possibly do a lot of transition from a state to another.
You didn't answer my question. If your application only spends 10% of its time actually transitioning states, then it doesn't really matter if you can speed that up by a factor of 2 or 10.

It is a good point.
I cannot say it right now that's why I did the dummy application.
It was just to have a rough idea abouut speed and fasteness in general.
Next time I will start with some data taken from it directly.
I hope to not have offended anyone with this small test / evaluation.
On Thu, Nov 26, 2009 at 5:23 PM, Eric J. Holtman
Conoscenza Silente wrote:
Whell I did a small test application to test the usage of boost::pool_allocator and boost::fast_pool_allocator. My application will possibly do a lot of transition from a state to another.
You didn't answer my question. If your application only spends 10% of its time actually transitioning states, then it doesn't really matter if you can speed that up by a factor of 2 or 10.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Also note that a lot of performance on ia32 can depend on cache
thrashing. You want to maintain memory locality otherwise you may get
confusing results. If you are using the wall clock for timing, keep an
eye on your disk light to as VM is not impossible without some care
but the cache may not be as appreciated.
This means parameter and data changes that cause flow or "small"
buffer size changes can make important differences in speed unrelated
to raw instruction or access count etc.
On 11/26/09, Eric J. Holtman
Conoscenza Silente wrote:
I hope to not have offended anyone with this small test / evaluation.
I'm not offended, just genuinely curious.
I'll admit it's possible to have an app that does spend a ton of time transitioning. I'm just not sure that's the case here.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- marchywka@gmail.com Mike Marchywka 586 Saint James Walk Marietta GA 30067-7165 415-264-8477 (w)<- use this 404-788-1216 (C)<- leave message 989-348-4796 (P)<- emergency only marchywka@hotmail.com Note: If I am asking for free stuff, I normally use for hobby/non-profit information but may use in investment forums, public and private. Please indicate any concerns if applicable. Note: hotmail is censoring incoming mail using random criteria beyond my control and often hangs my browser but all my subscriptions are here..., try also marchywka@yahoo.com

Thank you all very much!
CS
On Thu, Nov 26, 2009 at 7:29 PM, mike marchywka
Also note that a lot of performance on ia32 can depend on cache thrashing. You want to maintain memory locality otherwise you may get confusing results. If you are using the wall clock for timing, keep an eye on your disk light to as VM is not impossible without some care but the cache may not be as appreciated. This means parameter and data changes that cause flow or "small" buffer size changes can make important differences in speed unrelated to raw instruction or access count etc.
On 11/26/09, Eric J. Holtman
wrote: Conoscenza Silente wrote:
I hope to not have offended anyone with this small test / evaluation.
I'm not offended, just genuinely curious.
I'll admit it's possible to have an app that does spend a ton of time transitioning. I'm just not sure that's the case here.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--
marchywka@gmail.com Mike Marchywka 586 Saint James Walk Marietta GA 30067-7165 415-264-8477 (w)<- use this 404-788-1216 (C)<- leave message 989-348-4796 (P)<- emergency only marchywka@hotmail.com Note: If I am asking for free stuff, I normally use for hobby/non-profit information but may use in investment forums, public and private. Please indicate any concerns if applicable. Note: hotmail is censoring incoming mail using random criteria beyond my control and often hangs my browser but all my subscriptions are here..., try also marchywka@yahoo.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I've already played with the Statechart library. I think it's a good library but especially the fact that transitions take such a long time isn't good in many situations like embedded systems for instance. Of course Statechart has it's entitlement I think for you the new MSM library (currently in review progress) is worth a look. State machines build with MSM have very low overhead and are therefore very efficient. I've taken a simple example to this mail. On my machine the state machine with MSM is about 34 times faster than the one with Statechart. Conoscenza Silente schrieb:
Hi All Yesterday I started playing with Boost State Chart library implementing state machines for my applications. Each time I am moving into a new state I noticed that a new state is created; this means that the constructor of the boost::statechart::state class is called each time ( and the destructor for the state that I am leaving ).
I would like to fasten up the whole process; let's say that I would like to avoid the creation/destruction of the class each time using object already allocated in memory that are deleted only at the exit of the application. Is this a good way in your opinion ?
I saw that there is an allocator template argument but at the state where I am now I would lilke to not spend time in doing a new allocator for that: do you know if there already in place something that I can reuse for my purpose?
Thanks CS _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
#include
{}; struct event_2_3 : event< event_2_3 //, boost::fast_pool_allocator< event_2_3 > {}; struct event_3_4 : event< event_3_4 //, boost::fast_pool_allocator< event_3_4 > {}; struct event_4_1 : event< event_4_1 //, boost::fast_pool_allocator< event_4_1 > {};
struct state_1
: simple_state< state_1, main_machine >
{
typedef transition< event_1_2, state_2 > reactions;
};
struct state_2
: simple_state< state_2, main_machine >
{
typedef transition< event_2_3, state_3 > reactions;
};
struct state_3
: simple_state< state_3, main_machine >
{
//typedef transition< event_3_4, state_4 > arc; // it doesn't work
typedef transition< event_3_4, state_4 > reactions;
//state_3(){std::cout<<"3";}
//~state_3(){std::cout<<"~3";}
};
struct state_4
: simple_state< state_4, main_machine >
{
typedef transition< event_4_1, state_1 > reactions;
};
}
namespace msm = boost::msm;
namespace mpl = boost::mpl;
namespace test_msm // Concrete FSM implementation
{
struct event_1_2 {};
struct event_2_3 {};
struct event_3_4 {};
struct event_4_1 {};
// Concrete FSM implementation
struct main_machine_ : public msm::front::state_machine_def

"Conoscenza Silente"
I would like to fasten up the whole process; let's say that I would like to avoid the creation/destruction of the class each time using object already allocated in memory that are deleted only at the exit of the application. Is this a good way in your opinion ?
You might want to read the Performance section: http://www.boost.org/libs/statechart/doc/performance.html Bottom line: Unless you're writing a parser with Boost.Statechart, state construction & destruction usually doesn't constitute a perf bottleneck in an application. For parsing there are much more suitable tools (Spirit, Regex, etc.). HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
participants (5)
-
Andreas Huber
-
Conoscenza Silente
-
Eric J. Holtman
-
Franz Alt
-
mike marchywka