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

Disable all 3D nodes, physics, and resources when compiling without 3D #89381

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Mar 11, 2024

This PR disables all 3D nodes and resources, and ensures that some key files like World3D are not included anywhere, when compiling with 3D disabled. A summary of some of the changes:

  • World3D is now not included at all when 3D is disabled, so I removed the 3D disabled checks from that file.
  • PhysicsServer3D is not compiled when 3D is disabled.
  • PackedScene no longer includes Node3D when 3D is disabled.
  • Mesh no longer includes 3D physics shape generation methods when 3D is disabled.
  • NavigationMeshSourceGeometryData3D was including VisualInstance3D, but it only needed Mesh. I changed this to including only Mesh.
  • The above point broke NavigationServer3D and GodotNavigationServer3D since those need Node (but not Node3D), so I added a Node include for each of those.
  • ShaderGlobalsOverride included Node3D, but it only needs the tree notifications, so I switched it to Node.
  • RenderingLightCuller included Camera3D, but it does not need it, it only needs the core/math files.

Overall these changes are surprisingly clean, the last 4 bullets are just good fixes for including what you use. The big messy change is in the servers folder, with all the env.add_source_files lines in the SCsub file. I am of the opinion that we should move the server files into the server folders (like move PhysicsServer3D into the servers/physics_3d folder). But that should likely be a separate PR (maybe as a prerequisite to this one? or we can merge this first).

@akien-mga
Copy link
Member

akien-mga commented Mar 11, 2024

Changes look good to me.

Somewhat surprisingly though, this seems to make a disable_3d optimized build bigger than it was before.
Here's what I get with a local test with GCC 13.2.1:

-rwxr-xr-x. 1 akien akien  55515328 Mar 11 10:55 godot.linuxbsd.template_release.x86_64.disable3d
-rwxr-xr-x. 1 akien akien  55675040 Mar 11 11:15 godot.linuxbsd.template_release.x86_64.disable3d_pr89381
-rwxr-xr-x. 1 akien akien  64015424 Mar 11 11:00 godot.linuxbsd.template_release.x86_64.vanilla

Building with scons production=yes target=template_release disable_3d=yes scu_build=yes.

Not a big difference though, 156 KiB / 0.3% increase. But that's still a bit surprising when excluding more stuff.
And especially some analysis with bloaty had shown that PhysicsServer3D among other things was fairly big in a minimal build:

   0.5%  84.9Ki   0.5%  85.0Ki    servers/physics_server_3d.cpp

I tried without scu_build=yes as this may impact how well the linker removes unused code. The difference is smaller then, though still a tiny increase with this PR:

-rwxr-xr-x. 1 akien akien 55802016 Mar 11 11:53 godot.linuxbsd.template_release.x86_64.disable3d
-rwxr-xr-x. 1 akien akien 55818400 Mar 11 11:50 godot.linuxbsd.template_release.x86_64.disable3d_pr89381

Exactly 16 KiB increase, which is just 0.03%. So not very significant.

So overall this just seems not to have much impact on the binary size as is, which is a bit puzzling.


Tested on a super minimal build, no size difference:

-rwxr-xr-x. 1 akien akien 15576888 Mar 11 12:01 godot.linuxbsd.template_release.x86_64.master
-rwxr-xr-x. 1 akien akien 15576888 Mar 11 12:05 godot.linuxbsd.template_release.x86_64.pr89381

Built with

scons target=template_release production=yes disable_3d=yes disable_advanced_gui=yes optimize=size deprecated=no minizip=no modules_enabled_by_default=no module_gdscript_enabled=yes vulkan=no wayland=no build_profile=../blank.build

where blank.build is this build profile: blank.build.txt

@akien-mga
Copy link
Member

Tested a minimal build with debug symbols to run bloaty on:

scons target=template_release production=yes disable_3d=yes disable_advanced_gui=yes optimize=size deprecated=no minizip=no modules_enabled_by_default=no module_gdscript_enabled=yes vulkan=no wayland=no build_profile=../blank.build lto=none debug_symbols=yes separate_debug_symbols=yes

Without LTO (needed to have usable debug symbols), I do get a more significant size difference. So LTO seems to do a good job at removing unneeded 3D code even without this PR.

-rwxr-xr-x. 1 akien akien  19742192 Mar 11 12:29 godot.linuxbsd.template_release.x86_64.master
-rwxr-xr-x. 1 akien akien 267118528 Mar 11 12:29 godot.linuxbsd.template_release.x86_64.master.debugsymbols
-rwxr-xr-x. 1 akien akien  19590640 Mar 11 12:25 godot.linuxbsd.template_release.x86_64.pr89381
-rwxr-xr-x. 1 akien akien 264093200 Mar 11 12:25 godot.linuxbsd.template_release.x86_64.pr89381.debugsymbols

148 KiB removed, i.e. 0.75%.

master build:

$ bloaty bin/godot.linuxbsd.template_release.x86_64.master -d compileunits -n 0 --debug-file bin/godot.linuxbsd.template_release.x86_64.master.debugsymbols | grep 3d   0.4%  84.9Ki   0.4%  85.0Ki    servers/physics_server_3d.cpp
   0.2%  42.7Ki   0.2%  42.7Ki    servers/navigation_server_3d.cpp
   0.1%  17.2Ki   0.1%  17.2Ki    core/math/geometry_3d.cpp
   0.1%  9.72Ki   0.0%  9.74Ki    scene/resources/3d/concave_polygon_shape_3d.cpp
   0.0%  8.47Ki   0.0%  8.47Ki    servers/navigation/navigation_path_query_result_3d.cpp
   0.0%  6.16Ki   0.0%  6.16Ki    scene/resources/3d/shape_3d.cpp
   0.0%  6.16Ki   0.0%  6.16Ki    core/math/transform_3d.cpp
   0.0%  4.69Ki   0.0%  4.71Ki    scene/resources/3d/convex_polygon_shape_3d.cpp

This PR:

$ bloaty bin/godot.linuxbsd.template_release.x86_64.pr89381 -d compileunits -n 0 --debug-file bin/godot.linuxbsd.template_release.x86_64.pr89381.debugsymbols | grep 3d
   0.2%  42.7Ki   0.2%  42.7Ki    servers/navigation_server_3d.cpp
   0.1%  17.5Ki   0.1%  17.5Ki    core/math/geometry_3d.cpp
   0.0%  9.12Ki   0.0%  9.12Ki    servers/navigation/navigation_path_query_result_3d.cpp
   0.0%  6.16Ki   0.0%  6.16Ki    core/math/transform_3d.cpp

Full bloaty compileunits output for both builds:
bloaty_minimal_master.txt
bloaty_minimal_pr89381.txt

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Mar 11, 2024
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.

Confirmed building and testing works (i.e. does not introduce any regressions with debug templates and running tests)

@akien-mga akien-mga merged commit f040a35 into godotengine:master Mar 11, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@aaronfranke aaronfranke deleted the disable-3d branch March 11, 2024 21:32
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.

4 participants