godot icon indicating copy to clipboard operation
godot copied to clipboard

Don't include `core/io/image.h` in `core/os/os.h`

Open dustdfg opened this issue 1 year ago • 7 comments

core/os/os.h doesn't use core/io/image.h

It just brings to the code base transitive dependencies. Lots of dependencies because core/os/os.h is transitively included in almost every file of godot

How numbers were obtained. First of all thanks to this message in chat I knew about --tree=linedraw. So after compiling I run scons --tree=linedraw > /tmpt/godot.linedraw after that I needed to get actual number of includes of tested files. By running grep "<file>" /tmp/godot.linedraw | wc -l you get a number of files which directly or transitively depend on <file>

core/os/os.h core/io/image.h
Master 3040 3073
PR 3040 2650

Summary. With this PR compiler will need to process core/io/image.h 423 times less. Numbers were obtained on linux and will differ a little on different platforms because they doesn't share files inside platform folder.

It definitely should improve compilation speed but how much.... Maybe several microseconds, maybe several minutes. I can't check. One full build build from clean state takes 1.5~ hours on my machine so if you have a more powerful machine, could you please test if there is difference in compile times?

This PR also contains one minor change. core/core_bind.h didn't use core/io/image.h in any way as like all who includes it so this change doesn't depend core/os/os.h file

dustdfg avatar Oct 16 '24 13:10 dustdfg

I honestly doesn't know anything about Ref<Image> and didn't saw compiler errors which involve Ref at all and don't know what you are talking about ¯\_(ツ)_/¯

dustdfg avatar Oct 16 '24 15:10 dustdfg

This include is likely an old one from 3.x, a bunch of Ref<Image> function were in OS, but now are in DisplatyServer.

bruvzg avatar Oct 16 '24 15:10 bruvzg

The issue is explained here https://github.com/godotengine/godot/pull/80330#issuecomment-1666840873

AThousandShips avatar Oct 16 '24 16:10 AThousandShips

Honestly I can't say that I really understand Ref problem. Is the problem applicable only for forward declared things?

I removed forward declaration of Image inside display_server.h because it already included os.h which included image.h so IIUC there couldn't be problem with that forward declaration because the full definition also was pulled through os.h. Now there is no forward declaration at all so I want to believe there shouldn't be problem you describe.

dustdfg avatar Oct 16 '24 16:10 dustdfg

Are you sure there are no places that used to include this that have Ref<Image> and don't include the header? If yes then there's no problem, otherwise it is a risk and should have an include in the header as a replacement

AThousandShips avatar Oct 16 '24 16:10 AThousandShips

Are you sure there are no places that used to include this that have Ref<Image> and don't include the header? If yes then there's no problem, otherwise it is a risk and should have an include in the header as a replacement

It looks like there are some places where the potential problem exist. I am almost found an easy way to find them with grep and etc so I think I will solve them tomorrow. Thank you for explanations :smiley:

dustdfg avatar Oct 16 '24 18:10 dustdfg

Are you sure there are no places that used to include this that have Ref<Image> and don't include the header? If yes then there's no problem, otherwise it is a risk and should have an include in the header as a replacement

Now I am sure. Though I didn't add it to the files which include core/io/image.h or core/io/image_loader.h directly inside .cpp or in corresponding .h file with the same name

dustdfg avatar Oct 18 '24 16:10 dustdfg

Thanks!

Repiteo avatar Oct 21 '24 21:10 Repiteo