ShaderCompileWorker.exe's task priority is too low

(I have posted this a question on another section - I have decide to report it a bug here, original question [here][1] )

I have been investigating why Material Editor is running so poorly on my machine. Not the latest or fastest machine of its era, but not bad.

I have noticed that the task ShaderCompileWorker.exe is spawn with the OS priority of BelowNormal. Simply using the task manager to shift the priority to normal or higher makes a significant increase performance, from several minutes down to seconds.

Please review the two videos I have prepared the first shows the out of the box performance for material editor. I can forgive skipping ahead as it is nearly 3 mins long…but please appreciate how simple a change is being made to the material and how slow the process is…

The second shows me manually adjusting the priority, preview tasks complete extremely quickly once the priority has been changed.

I have spotted in source code for ShaderCompiler.cpp that the priority is hard coded:

I’m currently installing the requirements for rebuilding from source, and going through the recompile process myself, as you probably know this is quite a task…

1 Like

Rebuilt UE4 from source, after changing that line of code to use AboveNormal priority, seems to have fixed it for me.

Thanks so munch you safe my life

Excellent work!
Could you please share an executable file? (I have no compiler installed)
You may add it to the “releases” tab in a github repository.

You do not have to rebuild the engine from source, a much easier method is to just have the ShaderCompilerWorker program raise its own priority level on launch.

for example in ShaderCompilerWorker.cpp add this in the GuardedMainWrapper function:

#if PLATFORM_WINDOWS

		DWORD new_level = NORMAL_PRIORITY_CLASS;
		/*or ... */
		//DWORD new_level = ABOVE_NORMAL_PRIORITY_CLASS;
		HANDLE hproc = GetCurrentProcess();
		SetPriorityClass(hproc, new_level);

#endif

Download the engine source and make the changes listed above, Recompile the ShaderCompilerWorker project, then copy and paste the ShaderCompileWorker.exe from the source engine binaries output folder to your engine installation binaries folder.

Unreal Engine now has a [config option][1] for that, no need to recompile…

Engine/Config/BaseEngine.ini

[DevOptions.Shaders]

WorkerProcessPriority=-1 // change to 1

342757-screenshot-6.png

5 Likes