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

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

Merged

Conversation

dustdfg
Copy link
Contributor

@dustdfg dustdfg commented Oct 16, 2024

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 dustdfg requested review from a team as code owners October 16, 2024 13:26
@AThousandShips AThousandShips added this to the 4.x milestone Oct 16, 2024
@dustdfg dustdfg force-pushed the os_transitive_image_headers_refactor branch from 0a403fe to 6d22368 Compare October 16, 2024 13:56
@dustdfg dustdfg requested a review from a team as a code owner October 16, 2024 13:56
Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a compiler update, if it passes Github actions cicd it's fine.

I don't expect a speedup but it's neat on a clarity point of view.

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be safe, only risk is obscure compile errors in classes using Ref<Image>, did you cover all such cases specifically? If so then this should be proof against future changes and the only real risk is existing PRs that would need to be adjusted

@dustdfg
Copy link
Contributor Author

dustdfg commented Oct 16, 2024

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 ¯\_(ツ)_/¯

@bruvzg
Copy link
Member

bruvzg commented Oct 16, 2024

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

@AThousandShips
Copy link
Member

The issue is explained here #80330 (comment)

@dustdfg
Copy link
Contributor Author

dustdfg commented Oct 16, 2024

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.

@AThousandShips
Copy link
Member

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

@dustdfg
Copy link
Contributor Author

dustdfg commented Oct 16, 2024

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 😃

`core/os/os.h` doesn't use `core/io/image.h`. It just brings
transitive dependencies. Lots of dependencies because `core/os/os.h`
is transitively included in almost every file of godot

Also added `core/io/image.h` into files^1 where `Ref<Image>` and `core/os/os.h`
were used to prevent obscure errors involving `Ref<Image>`

^1 except those which include `core/io/image_loader.h` or `core/io/image.h` by
corresponding .h file with the same name

Signed-off-by: Yevhen Babiichuk (DustDFG) <dfgdust@gmail.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
@dustdfg dustdfg force-pushed the os_transitive_image_headers_refactor branch from 6d22368 to af6d260 Compare October 18, 2024 16:07
@dustdfg dustdfg requested review from a team as code owners October 18, 2024 16:07
@dustdfg
Copy link
Contributor Author

dustdfg commented Oct 18, 2024

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

@Repiteo Repiteo removed this from the 4.x milestone Oct 19, 2024
@Repiteo Repiteo added this to the 4.4 milestone Oct 19, 2024
@Repiteo Repiteo merged commit 291e4b7 into godotengine:master Oct 21, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 21, 2024

Thanks!

@dustdfg dustdfg deleted the os_transitive_image_headers_refactor branch October 25, 2024 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants