Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threaded function is unusual slow under some conditions #86796

Open
IceflowRE opened this issue Jan 4, 2024 · 4 comments
Open

Threaded function is unusual slow under some conditions #86796

IceflowRE opened this issue Jan 4, 2024 · 4 comments

Comments

@IceflowRE
Copy link
Contributor

Tested versions

v4.2.1.stable.official [b09f793]

System information

Godot v4.2.1.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 Ti (NVIDIA; 31.0.15.4633) - AMD Ryzen 9 7900X 12-Core Processor (24 Threads)

Issue description

I tried to use ImageTexture.create_from_image in a thread and was surprised that the performance is around 10x slower than when being used in the main thread.

If the line self._load_progress = float(idx) / 2000.0 * 100.0 is removed or commented out, the threaded performance drops to 30x slower.

Might be related to #36793.

Steps to reproduce

Just run the attached project.
Results are printed to log.

Minimal reproduction project (MRP)

MTSlow.zip

@IceflowRE IceflowRE changed the title Thread function is unusual slow under some conditions Threaded function is unusual slow under some conditions Jan 4, 2024
@smix8
Copy link
Contributor

smix8 commented Jan 4, 2024

Creating new textures or changing and receiving image data stalls the RenderingServer as data need to be received from or updated on the GPU. You are basically pulling the handbrake on the rendering loop at that point that needs to lock when you query the server api like that randomly from a thread so bad performance is expected.

@IceflowRE
Copy link
Contributor Author

IceflowRE commented Jan 8, 2024

What is the alternative? If there is any.

@AThousandShips
Copy link
Member

Try enabling threaded rendering, though it has its drawbacks and instabilities, otherwise don't do it on a thread but on the main thread on request, just generate the data on the thread, you're not going to be able to pass the data to the rendering device at the same time anyway due to communication channels AFAIK, so set up the data and request it to be updated on the main thread, as a producer/consumer setup

@IceflowRE
Copy link
Contributor Author

IceflowRE commented Jan 9, 2024

Try enabling threaded rendering, though it has its drawbacks and instabilities

This wont be possible, it is used in a plugin.

otherwise don't do it on a thread but on the main thread on request, just generate the data on the thread, you're not going to be able to pass the data to the rendering device at the same time anyway due to communication channels AFAIK, so set up the data and request it to be updated on the main thread, as a producer/consumer setup

The consumer/producer could work, but would increase the complexity a lot, especially when loading 10k or 20k of textures.
As i should not load it in one frame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants