Spawn time using SpawnSplineMesh node in PCG runs much slower in 5.7 compared to 5.5

There seems to be a big problem when using the SpawnSplineMesh node in the PCG enviroment.

The issue is as it seems to be with how the SplineMeshComponent is being gotten in 5.5 compared to 5.7.

in 5.7 version at every frame of the generation it runs GetOrCreateManagedSplineMeshComponent which in turn

runs get component once at the beginning, the next frame it runs again and now it runs get component 2 times.

This trend continues through the whole generation so at the end it runs GetComponent on SplineMeshComponent

once for each splinemesh created earlier, this makes pcg slow down considerably and in turn the next piece takes

even longer to generate.

This version is non blocking and the editor continues running.

Now if we swap over to 5.5 instead when the generation now runs GetOrCreateManagedSplineMeshComponent there

is no get component as far as i could see from the profiler and instead it uses a previously cached SplineMeshComponent. This is

what i think makes this version in general way faster because its consistant across generation.

This version is blocking so the editor can not be used which is good if you generate a random level like what

we need and to make it as fast as possible.

The end goal is to make the 5.7 version blocking in the generation so that the road can generate really fast

while a loading screen is up.

Please see attached image of the profiler. Behavior is similar in editor and packaged project.

If there is just a setting or a flag that has been missed to make it blocking that would be amazing to know about.

The attached repro projects are clean default projects that will show the issue when compared. Please note that we tested 5.6 as well and it seems to behave the same as 5.7.

Thank you

Traces.zip(151 MB)

Steps to Reproduce

  1. Open attached projects side by side.
  2. Enter PIE.
  3. Press space to start PCG generation.
  4. Notice how the 5.7 project generates slower the more spline meshes are spawned (compared to 5.5).

Hi Troels,

Thanks for reaching out. We’ll have a look at the traces and see how we can make this behave better.

In the mean time, I wonder if you could bump up the frame time while you’re on the loading screen - maybe that would attenuate the effect at least.

In editor that cvar is pcg.EditorFrameTime and at runtime it’s pcg.FrameTime.

Hope this helps,

Julien

Thank you very much for the response Julien!

Setting the pcg.FrameTime definitely helps with overall generation time of the road.

However, we still have the problem where it does still go slower as it generates more roads, so the above helps alot but still not at the level of previous version 5.5.

Looking forward to your response thank you

Troels

Hi!

We have a few things to check that should improve performance, like restoring a cached ptr, but not as raw but as weak.

In the question there is a mention about some projects attached, but I can only see the traces. Could you upload them here?

Have a great day!

Adrien

Hi Adrien, thank you - Sure thing I’ve attached the projects to this reply. I thought I attached them to the initial post, not sure what went wrong

Best

Troels

Projects.zip(46.1 MB)

Thanks a lot!

So after analysis of the perf with your project, caching the component as a weak ptr on the managed resources close the gap to 5.5 generation time, so it is a quick win.

Though I think that the Spline Mesh Spawning should somewhat be optimized, as it is definitely not efficient. But at least this small change restore 5.5 performance, so we’ll go with this for now.

As it requires a header change I won’t be able to push it as a hotfix, but I can link you the git commit sha when it is submitted in main.

Adrien

Thanks for looking in to this Adrien, I’m happy to hear it was an easy tweak! And a link for the git commit would be highly appreciated.

Have a great day and talk later :smiley:

Troels

Hey there :slight_smile:

Here is the git commit on UE5-main: https://github.com/EpicGames/UnrealEngine/commit/4517584489ee2608e8de6f162e65901554c134a5

Hope this will solve your performance issue! Keep us posted if you still have issues with the spline mesh re-use

Have a great week

Adrien

Thanks so much Adrien !! :smiley: Really appreciated.

Have an awesome week!