Make it work, Make it right, Make it fast is a very good mantra.
Which is how we implement new features in SFGUI too.
As Tank said, how it is now I'd say the computation time ratio between HandleEvent() and Expose() is probably <1/99 and both make up almost all the time the library needs. Separating event handling and rendering into 2 different threads won't help much unless you plan on passing many MANY events to the library. In that case I would seek the source of the problem elsewhere
.
The only way you can make SFGUI less of a bottleneck is therefore by speeding up Expose(). Since I've been optimizing the performance of the library lately, I can tell you that SFGUI isn't even the culprit of the long time spent in Expose(). In fact 1 level down the calltree and you'll only find calls to SFML which is where Expose() lingers for almost all of it's time. Since SFML renders through OpenGL it also wouldn't make sense to try to optimize there. As explained nice and short here:
http://www.opengl.org/wiki/OpenGL_and_multithreading if you only have 1 GPU all the calls to GL from multiple threads will end up in 1 queue anyway, thereby wasting any effort to render from different threads.
The #1 bottleneck is therefore SFML and it relies on GL calls which don't make sense to separate into multiple threads. If you want a performance increase with SFGUI I would rather talk to Laurent first than try to parallelise everything you can in SFGUI. If he can reduce the amount of GL calls per shape/text trust me, you won't have performance issues with SFGUI ever again
.
As always I let numbers speak for themselves. Here is the top 10 list from the flat gprof profile of Test.cpp:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
9.08 0.82 0.82 16418394 0.00 0.00 sf::Renderer::ProcessVertex(float, float, float, float, float, float, float, float)
9.08 1.64 0.82 tt_cmap4_char_map_binary
7.25 2.29 0.66 175952 0.00 0.03 sf::Text::Render(sf::RenderTarget&, sf::Renderer&) const
6.31 2.87 0.57 16418394 0.00 0.00 sf::Matrix3::Transform(sf::Vector2<float> const&) const
6.09 3.42 0.55 tt_face_get_kerning
4.87 3.85 0.44 3419834 0.00 0.00 sf::Texture::GetTexCoords(sf::Rect<int> const&) const
4.32 4.25 0.39 32168534 0.00 0.00 std::less<unsigned int>::operator()(unsigned int const&, unsigned int const&) const
3.88 4.59 0.35 3421964 0.00 0.00 std::_Rb_tree(std::_Rb_tree_node<std::pair<unsigned int const, sf::Glyph> >*, std::_Rb_tree_node<std::pair<unsigned int const, sf::Glyph> >*, unsigned int const&)
3.88 4.95 0.35 3417478 0.00 0.00 sf::Renderer::AddVertex(float, float, sf::Color const&)
2.77 5.20 0.25 32967353 0.00 0.00 sf::Vector2<float>::Vector2(float, float)
The first SFGUI call ( Expose() ) comes at position 25:
0.72 7.03 0.07 374017 0.00 0.02 sfg::Widget::Expose(sf::RenderTarget&)