Blueprint vs C++ performance .

Benchmark UE4 Performance: C++ vs Blueprint

Sorry for bumping this post, however it is an important question for many of us. As many have stated, I was also expecting blueprint to be much slower than c++, but to make a long story short, I had a 100% Blueprint project, I decided to rewrite it completely in c++, using only Blueprint as a commodity for appearance / positioning / simple interactions. I had a performance boost, but nothing spectacular, even though I optimized my c++ code (I am a computational scientist with 15 years experience).

Since I had a mixed feeling and I was still unsure of the performance loss due to BP, I finally decided to create a new and very small project: 1 pawn in c++, the exact same in BP, each pawn with a simple method to move the pawn (interesting for AI simulations).

Here are the results, each value has been computed at least 3 times to lower artifacts:

For 400 actors:

  • in Editor: 79 fps (c version) vs 69 fps (blueprint version)
  • Package (ship): 156 fps (c version) vs 157 fps (blueprint version) (no simulation: 180 fps)

For 800 actors:

  • in Editor: 49 fps (c version) vs 43 fps (blueprint version)
  • Package (ship): 80 fps (c version) vs 78 fps (blueprint version) (no simulation: 115 fps)

For 1200 actors:

  • in Editor: 36 fps (c version) vs 31 fps (blueprint version)
  • Package (ship): 65 fps (c version) vs 60 fps (blueprint version) (no simulation: 95 fps)

For 1200 actors (no mesh):

  • in Editor: 59 fps (c version) vs 47 fps (blueprint version)
  • Package (ship): 160 fps (c version) vs 132 fps (blueprint version) (no simulation: capped value at 200 fps)

For 2400 actors (no mesh):

  • in Editor: 33 fps (c version) vs 24 fps (blueprint version)
  • Package (ship): 71 fps (c version) vs 60 fps (blueprint version) (no simulation: 95 fps)

Notes:

  • Tests realized on UE 4.12.5
  • I put t.maxFPS to 200 fps for those tests, so 156 fps is 156 fps, not a capped value
  • XXX actors: means XXX actors are simulated, but the scene contains twice that number (C++ actor + BP actor)
  • Checking Stat Unit, the Game Thread was always the limiting factor, but the more actors the scene contains, the more it bias the comparison C++ vs BP
  • Hence, above 1200 actors, I remove the cube mesh of each actor, then only the Game Thread was limiting.
  • Packaging in Development rather than Shipping mode influences those results: with 800 actors, I was roughly at 69 fps for both c++ and bp versions instead of the 80/78 fps in Shipping mode.

Conclusions:

  1. ok package versions much faster, logical since no overhead from editor :slight_smile:
  2. inside the editor, yes blueprint is always slower than C++ (10-40%)
  3. inside the editor, the more actors you have, the more differences you will see between BP and C++ (at 2400 actors: BP 37,5% slower than C++, at 1200 actors: 25,5%)
  4. in packaged versions, the differences between BP and C++ versions are much smaller: 8% for 1200 actors with mesh. But at 1200 actors with mesh, the Draw Thread is influencing the fps.
  5. to remove the impact of Draw Thread, I removed the mesh of those 1200 actors. Stat unit & the 200 fps count confirmed that only the Game Thread is driving the fps. When starting the simulation, the frame rates drops from 200+ to 160 fps for the C++ version and 132 fps for the BP version. We can consider this result as a 21% brute gain performance of using C++ over BP.

For completeness, I added several computations during the simulation (cos, sin, pow, random, etc).

  • At 1200 actors with mesh the limiting factor is now again the Game Thread (due to added computations)
  • As always in the editor, BP is much slower than C++. Before adding these computations, BP were 16% slower, now they are 28% slower with the added computations
  • In the packaged (ship) version however, the result is consistent with the Conclusion 5). With those added computations, the C++ version runs at 49 fps while the BP version runs at 40 fps. In other terms, C++ shows a 22% brute gain performance over BP

**Global Conclusions: ** (only concerns packaged version as editor doesn’t matter for final products)

  • Yes, C++ is faster than BP
  • BUT C++ is not at all 10 times faster than BP, even for pure computations. If anyone as a test case showing this 10 times faster I would be very interested to see that
  • In my tests, the gain of using C++ for specific computations was roughly 20%. I don’t expect this gain to be more than 30%, even for stronger computations
  • BP is surprisingly very fast, I’ve read somewhere the development team is working on translating BP in C++, perhaps is it already partially done ? Anyhow BP is just an interface to actually call the C++ codes of UE4 platform.
  • I would advise to use C++ only when tremendous calculations are involved as the performance gain is not as important as one would expect / hope OR when you need more flexibility than Blueprint for your project architecture. Note BP is still very flexible.

For me, UE4 Blueprints are a true technical success.

In the end, it’s your optimized algorithm that makes a true difference.

Cheers,

9 Likes