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

[low prio] [feature inquiry] Performance CFLAGS (-O2, -march=native, etc.) #614

Closed
stradicat opened this issue Sep 21, 2023 · 6 comments
Closed
Assignees

Comments

@stradicat
Copy link
Contributor

stradicat commented Sep 21, 2023

Hi!

I've noticed that emacs-plus is built by default with -Os, which tries to minimize code size while optimizing towards -O2 level.

However, since the hardware where Homebrew runs has large-ish cache sizes (oldest officially BigSur-compatible machines have 256kb of L2 & 3Mb of L3 caches, like the 2013 11-inch MacBook Air), is there a specific reason not to go with -O2? (At least when building --with-native-compilation)
I was also wondering if adding -march=native would make sense, since the formula is compiled on the destination machine anyway.

For comparison, the following options are enabled on Linux builds of Emacs: (Ubuntu case, kelleyk PPA)

CFLAGS="-pipe -O2 -flto=auto -ffat-lto-objects -fstack-protector-strong"
CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2"
LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro"

@d12frosted
Copy link
Owner

Hey @stradicat

Thanks for raising this question. To be honest, Emacs+ doesn't do anything special with O flags. You can check the source code of the formula. So we are using whatever Emacs build tools are using.

is there a specific reason not to go with -O2?

There is no specific reason 😄 So it would be a nice contribution.

I was also wondering if adding -march=native would make sense, since the formula is compiled on the destination machine anyway.

Not aware of this flag. What does it do? If my intuitive understanding is correct, it's OK to add this for cocoa flag (some people use Emacs+ on Lunux).

@stradicat
Copy link
Contributor Author

stradicat commented Oct 3, 2023

Thanks for looking into this!

In Linux packages, -O2 is a commonly used optimization flag for Emacs compilation, which optimizes space-speed tradeoff; the resulting compiled executable runs a bit faster than -Os (optimized for code size, same as emacs-plus' defaults), and it's more noticeable on older machines (I'm still using an Intel Mac with OpenCore Legacy Patcher, and I also compile Emacs from source on some i386 PCs).
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Since emacs-plus is compiled from source and the host machine is its own target, throwing in -march=native enables/disables optimization flags following the host's own CPU architecture, more often than not improving execution speed by a margin.

Taking into account that Emacs is an interpreter, above all, this can give it a small performance edge, noticeable in terms of latency related to user input.

What do you think?

@stradicat
Copy link
Contributor Author

Better yet: I'll run some measurements and come back with a PR.

@d12frosted
Copy link
Owner

What do you think?

What you say makes total sense. So I will be happy to see your PR 😸

P.S. Thanks for explanations 🙏

@stradicat
Copy link
Contributor Author

Closing since #698 was accepted :)

@d12frosted
Copy link
Owner

Indeed, completely forgot to close the original "issue" 😅 thanks!

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

2 participants