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

Use noexcept modifier where it's possible to improve engine performance #3302

Closed
Chaosus opened this issue Sep 16, 2021 · 4 comments
Closed

Comments

@Chaosus
Copy link
Member

Chaosus commented Sep 16, 2021

Describe the project you are working on

Godot

Describe the problem or limitation you are having in your project

No, it just can improve the engine performance.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

noexcept is a C++ 11 feature (https://en.cppreference.com/w/cpp/language/noexcept) that can significantly increase the code performance due to enabling compile optimization by omitting the internal exception checking. Since Godot already does not have any exception handling by telling the compiler to not check it internally I think the result will be significantly better.

See also a discussion about it: https://stackoverflow.com/questions/10787766/when-should-i-really-use-noexcept

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

By adding noexcept definition to all function declarations/definitions, constructors and operators (excluding third-party code of course). Probably that should perform automatically using some tool.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

It's a core thing by default

@Calinou
Copy link
Member

Calinou commented Sep 16, 2021

As with any code change that relies on compiler specifics, make sure to benchmark the performance difference in real world scenarios to see if it's actually worth doing 🙂

Since Godot is always compiled without exceptions, so I don't think there is such a thing as a function that couldn't be made noexcept anyway.

@KoBeWi
Copy link
Member

KoBeWi commented Sep 16, 2021

According to the discussion you linked, the compiler can deduce if it should handle exceptions or not, and since we never use them, most likely Godot is already optimized on this regard.

Also adding noexcept to every single function is kind of meh. I wonder if there is a global compiler flag for that.

@Artromskiy
Copy link

I wonder if there is a global compiler flag for that.

-fno-exceptions can be used.

@Chaosus
Copy link
Member Author

Chaosus commented Mar 21, 2023

Okay, seems like this can be achieved by the compiler flags and there is no need to pollute the code with it.

@Chaosus Chaosus closed this as completed Mar 21, 2023
@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2023
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