Noticable performance loss with State specific dispatchers?

#1

First of all, Hello!

I usually hang out on Discord and harass the folks in the #help channel there, but I figured I can’t constantly hog the channel for every single question I have. So… here I am with my first post on here!

I implemented a State specific dispatcher, which for the most part works just fine. But the System s inside that dispatcher seem to get executed less frequently. I followed the example in the book and have the following update function in my State:

fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans {
    data.data.update(&data.world);
    self.dispatcher.as_mut().unwrap().dispatch(&data.world.res);
    Trans::None
}

I checked against an older implementation of my game which had a single dispatcher and when I printed time.delta_seconds() inside a System s run() function I’d get these values:

0.014552852
0.019336691
0.01406074
0.014382324
0.016266558

With the State specific dispatcher the System (which is part of the State dispatcher) prints the following:

0.032316934
0.03341968
0.033265237
0.033323724
0.033561807

When I comment out data.data.update(&data.world); in my update function I get similar values again… but I don’t think it’s a good idea to leave that part out.
I’m currently testing in debug mode… I could try release but I find the difference on debug bad enough and don’t want to rely on release for development.

My source code can be found here:


src/states/game.rs has its own dispatcher.

Am I missing something or are State specific dispatchers simply slower?

1 Like

(Théo Degioanni) #2

You should try out running it in release mode first. Debug mode has sometimes surprising and hard to decipher performance issues as the underlying abstractions in Amethyst are very complex and are heavily optimized by release mode.

Of course having a state-specific dispatcher is somewhat slower as it has to run after the main dispatcher, separately. But it should not be that much slower.

1 Like

#3

Thanks for your response! I actually just figured out what the problem was with the help of @distransient. Since I’m using the default GameData, the core dispatcher is already executed by the Application and thus the line data.data.update(&data.world); causes the core dispatcher to be executed twice before my custom State dispatcher. Removing data.data.update(&data.world); fixed it.

2 Likes

#4

Created a PR to change that part in the master book:

1 Like