Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Low performance with boost::statechart

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Rain Dog Posted - Aug 01 2008 : 5:18:36 PM
I get pretty low editing performance using the lastest version of VAX (10.4.1647.0) when editing a file contaning boost::statechart related code.

I just started with this file and am in the process of also learning boost::statechart so the code might be rather poor quality atm, but editing it is slow regardless. I am experiencing up to 1 second delays when typing even comments into this file.

The headers for the file are in my pch. (stdafx.h)


Below is the code.


#pragma once

namespace NavigatorStatemachine
{

	namespace sc = boost::statechart;

	//statemachine do
	struct navigator;

	//superstate :traveling
	struct idle;

	struct stop : sc::event < stop >{};
	struct suspend : sc::event< suspend >{};
	struct travel : sc::event< travel >{};
	struct tick : sc::event< tick >{};
	struct traveling : sc::simple_state<traveling, navigator, idle>
	{
		typedef mpl::list<
			sc::transition<>,
			sc::transition<>,
			sc::transition<>,
			sc::transition<>,
			sc::custom_reaction<>

		>
			

		//event stop, idle, stop_moving
		sc::result react(const stop &);

		//event suspend, suspended
		sc::result react(const suspend &);

		//trans idle, travel, moving_to_wp, init_mover
		//trans moving_to_wp, stop, stop_mover
		//trans idle, tick, idle, update_positiojn
		//trans idle, arrived, idle

		//start_state idle
	};

	//superstate :moving_to_wp
	struct moving;
	struct stopped;
	struct wp_reached : sc::event< wp_reached >{};

	struct moving_to_wp : sc::simple_state<moving_to_wp, traveling, moving>
	{
		typedef mpl::list<
			//event wp_reached, has_arrived
			sc::transition<wp_reached, has_arrived>,
			sc::custom_reaction<stop, stopped>
		> reactions;


		//event stop, stopped, stop_moving
		sc::result react(const stop &);

		//startstate moving
		moving_to_wp()
		{
			//on_entry start_moving
		};
	};

	struct not_reached_wp : sc::event< not_reached_wp >{};
	struct position_updated : sc::simple_state<position_updated, moving_to_wp>
	{
		typedef sc::custom_reaction<not_reached_wp> reactions;

		//event not_reached_wp, moving, correct_movement
		sc::result react(const not_reached_wp &);

		position_updated()
		{
			//on_entry check_position
		};
	};

	struct arrived : sc::event<arrived>{};
	struct not_arrived : sc::event<not_arrived>{};
	struct has_arrived : sc::simple_state<has_arrived, traveling>
	{
		typedef mpl::list<
			sc::custom_reaction< arrived >,
			sc::custom_reaction< not_arrived> 
		> reactions;
		//event arrived, idle, stop_mover
		sc::result react(const arrived &);
		//event not_arrived, moving_to_wp, move_to_next_waypoint
		sc::result react(const not_arrived &);

		has_arrived()
		{
			//on_entry check_progress
		};
	};

	//superstate stuck
	struct checking_stuck_state;
	struct unsticking;
	struct unstuck : sc::event< unstuck >{};
	struct still_stuck : sc::event< still_stuck >{};
	struct tick : sc::event< tick >{};
	struct stuck : sc::simple_state<stuck, traveling, unsticking>
	{
		typedef mpl::list<
			sc::custom_reaction<unstuck>,
			sc::custom_reaction<still_stuck>,
			sc::transition<tick, checking_stuck_state>
		> rections;

		//trans checking_stuck_state, unstuck, moving_to_wp
		sc::result react(const unstuck &);

		//trans checking_stuck_state, still_stuck, unsticking, unstick_me
		sc::result react(const still_stuck &);

		//trans unsticking, tick, checking_stuck_state
		sc::result react(const tick &);

		stuck()
		{
			//on_entry init_stuck_stuff
		}
	};

	struct checking_stuck_state : sc::simple_state<checking_stuck_state, stuck>
	{
		checking_stuck_state()
		{
			if(/*stuck*/ true)
			{
				transit<moving_to_wp>()
			}
			else
			{
				transit<
			}
		}
	};

	struct navigator : sc::state_machine<navigator, traveling>
	{
		int start_moving();

		int correct_movement();
		int stop_moving();

		//state has_arrived
		int stop_mover();

		//trans suspended, resume, traveling_H
		//context waypoint_context (this)
		//startstate traveling
	};

};



//Superstate example.

//Forward declare start state:
struct Foo;
//Declare statemachine:
struct FooMachine : sc::state_machine<FooMachine, Foo>
{
	//Context related functionality here.

	int get_guard_value()
	{
		return 1;
	}
};

//forward declare inner states;
struct Bar;
struct Baz;

//declare events:
struct EvFoo : sc::event< EvFoo >{};
struct EventQux : sc::event < EventQux >{};
struct EventQuux : sc::event< EventQuux >{};

//Declare superstate:
struct Foo : sc::simple_state<Foo, FooMachine, Bar> //bar is start state of superstate.
{
	//Declare transitions and reactions to events using mpl::list
	typedef mpl::list<
		//declare a custom reaction that is not merely a simple transition. IE, we have an 'action'
		sc::custom_reaction< EvFoo >,

		//declare simple transition. params: event, final state
		sc::transition< EventQux, Qux>,

		//do some action prior to the transition.
		sc::transition< EventQuux, Qux, Foo, &Foo::QuuxAction >
	>

	//on_entry action
	Foo()
	{
		std::cout << "performed entry action" << std::endl;
	}

	//on_exit action
	~Foo()
	{
		std::cout << "performed exit action" << std::endl;
	}

	void QuuxAction( const EventQuux &)
	{
		std::cout << "this is the shizznizzle" << std::endl;
	}

	//Declare handler for custom reaction;
	sc::result react(const EvFoo &evt)
	{
		//Use a guard:
		int guard_val = context<FooMachine>().get_guard_value();
		switch(guard_val)
		{
		case 1:
			//swallow event
			discard_event();
			break;
		case 2:
			//Take some transition action and end at state Qux.
			return transit< Qux >( &Foo::stupid_action, evt );
			break;
		default:
			//transition from state Foo to state Qux.
			return transit<Qux>();
		}
	};

	void stupid_action( const EvFoo &evt)
	{
		std::cout << "stupid reaction on event" << std::endl;
	}

};

//declare states, 2nd param is outter/parent state.
struct Bar : sc::simple_state<Bar, Foo>
{

};

struct Baz : sc::simple_state<Baz, Foo>
{

};

//Declare global state IE: parent state is the statemachine
struct Qux : sc::simple_state<Qux, FooMachine>
{

};
8   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Aug 14 2008 : 09:53:49 AM
I would not expect a corrupt NCB file to cause CPU usage like this, but can you try disabling the IDE's intellisense scanner for your main solution and see if this makes any difference? I have certainly seen the intellisense scanner in VS2005 cause this sort of slow down in large C++ solutions:

http://docs.wholetomato.com?W133
znakeeye Posted - Aug 13 2008 : 6:02:46 PM
Try deleting the .ncb-file. VS screws up its internal database quite often...
Rain Dog Posted - Aug 13 2008 : 3:15:37 PM
It seems that the editing issue I had is not present in the solution you created. I even added boost not to the IDE include paths, but to the projects additional include directories and editing performance was acceptable.

I will continue to work to see if I can find something more useful to assist in helping root cause this issue.
feline Posted - Aug 12 2008 : 10:32:42 AM
I have created a new VS2005 C++ console project and added your sample code to it. So far I am not seeing any problems. I have uploaded it as a zip file:

http://forum.wholetomato.com/colin/forumimages/8077_cpp_console_statechart.zip

Can you download and open this project please, and see if you can reproduce the problems?

Note I have not added boost to this projects additional include directories, since I have added boost to the IDE's include directories instead.
Rain Dog Posted - Aug 11 2008 : 4:11:02 PM
No, you shouldn't have to do anything besides editing the file and using the up/down arrow keys to navigate between lines to add more code. Try adding some cout statements somehwhere.
feline Posted - Aug 11 2008 : 12:05:23 PM
using VS2005 and VA 1647 I have added a new header file to my project and added both the #include statements and this code to the file.

I am now using Boost 1.35 and I have added the directory:

C:\\boost\\boost_1_35_0;

to VA's list of stable include directories.

I am not seeing any delay or CPU usage spike when typing comments into this file. I have tried 8 different places in the file, the very top, the very bottom, and several places in the middle of the file.

I am seeing a CPU spike when using page up / page down to scroll through the file, but that is it.

Am I doing something wrong? Do I have to type a specific comment in a specific place in the file?
Rain Dog Posted - Aug 09 2008 : 6:43:05 PM
#include <boost/statechart/event.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/custom_reaction.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/mpl/list.hpp>


I am using the latest (1.35) version of boost. Version 1.33.1 is very old now btw and they are nearing release of v1.36

Note also that there are some compilation errors in the snippet I posted, but fixing them all did not result in faster editing speed.
feline Posted - Aug 04 2008 : 10:35:36 AM
Which version of boost are you using?
Which header files do I need to include? A find in files across boost 1.33.1 is not turning up any header files that will help with this code.

Is all of this code from a single header file, or is it split across more than one file?

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000