reddit / emacs

Emacs 28.1, Windows, Native Comp Newbie questions

EmacNoob · 2022-04-14 18:08
All my work is in Windows. I saw a post the other day about Windows binaries with AOT. Some questions I've been trying to figure out: \- Native comp'd files are .eln (as opposed to .elc). Does it work like before, the .eln lives along side the .el? \- Does it just speed up load time, or is there performance improvement even after it's been loaded? \- Do the Emacs 28 binaries on the GNU FTP server have Native Comp? \- Is AOT something different than Native Comp? It compiles in the background? \- How do I Native Comp an .el file? Byte-Compile as usual?? ​ Sorry for the super newbie questions.
lebensterben · 2022-04-14 18:49
just try out. it doesn't hurt and you'd soon found that most of your questions can be resolved by yourself.
Soupeeee · 2022-04-14 18:54
Native compilation should occur in the background as functions are loaded. At least that's what happens on my Linux version. I'm not sure that the official emacs binaries on windows come with native comp enabled. I run emacs on both Linux and Windows, and there are no buffers with a native compilation log on windows, unlike what is seen on Linux. Plus, running `disassemble` on Linux will actually show assembly instead of bytecode for natively compiled functions, and I have yet to see that with any functions I have looked at. The binary does ship with some eln files, so it's partially there, but I haven't been able to figure out if they are actually used for anything.
Horrih · 2022-04-14 19:08
The feature is enabled, at least running one of the native comp commands does not throw an error like it does on archlinux where it's not enabled. However it did not work on my side : i guess you need libgccjit or an equivalent installed besides your emacs
telenieko · 2022-04-14 19:15
The offical Windows builds do have native compilation enabled. Buy you will need MSYS2 & libgccjit for it to work: `pacman -S mingw-w64-x86_64-libgccjit` Nothing else needed (maybe gcc if it's not installed automatically?)
[deleted] · 2022-04-14 19:17
[deleted]
telenieko · 2022-04-14 19:17
Well, you will also need to update your PATH to include MSYS2 binaries (default: `C:\msys64\mingw64\bin`)..
[deleted] · 2022-04-14 19:29
I run the Emacs with native comp but the developmental version. I followed this link and Phils solution: [https://emacs.stackexchange.com/questions/61775/is-there-a-gccemacs-native-comp-build-for-ms-windows](https://emacs.stackexchange.com/questions/61775/is-there-a-gccemacs-native-comp-build-for-ms-windows) I have not noticed any difference is speed between this and standard Emacs EXCEPT when handling very large files. Then native comp is noticeably faster. I would like to see an Emacs release with this working "out of the box" without the need to use compile options and customize things.
EmacNoob · 2022-04-14 19:37
Ah! Thank you. I installed MSys and was missing it in the PATH. That did the trick, it's working for me now.
briang_ · 2022-04-14 19:37
All my work in in Linux, so as a Windows user, you should treat all my answers carefully :) >Does it work like before, the .eln lives along side the .el? Not quite the same. The `.eln` files are all stored together in a single directory (`.emacs.d/eln-cache`). >Is AOT something different than Native Comp? It compiles in the background? AOT is *Ahead Of Time*. If AOT is enabled, some (all?) elisp files in the source distribution are compiled to `.eln` in advance, as opposed to being compiled as required. AOT is carried out as part of building emacs from source (and it *really* increases build time). As far as I know, emacs 28 no longer includes AOT. >Does it just speed up load time, or is there performance improvement even after it's been loaded? I don't know if it speeds up load time, but there's definite speed up during use. If you're concerned about load times, use [emacs server mode](https://www.emacswiki.org/emacs/EmacsMsWindowsIntegration#h5o-9). >How do I Native Comp an .el file? Byte-Compile as usual?? You shouldn't need to do it manually. It should all be automatic.
mplscorwin · 2022-04-14 20:02
>\- Native comp'd files are .eln (as opposed to .elc). Does it work like before, the .eln lives along side the .el? In works exactly like normal byte-compilation *except* that the ELN files don't live next to the EL files (like the ELC files do), but rather are in a folder named with an hashed value specific to build version. This distinction is probably only important if you are peeking at the system or trying to move things around "manually". ​ > \- Does it just speed up load time, or is there performance improvement even after it's been loaded? The performance improvement should be felt anytime you use computationally intensive functionality from a given natively complied package/elisp source file. ​ > \- Do the Emacs 28 binaries on the GNU FTP server have Native Comp? Yes, they do. As another has commented, unless you've setup gcc and libgccjit (including adjusting your PATH), however, you will only be able to use the (few) ELN files included with the binary distribution. ​ > \- Is AOT something different than Native Comp? It compiles in the background? AOT refers to "Ahead of Time". For the windows binary distributions, this means users can load and use the ELN files provided without needing to setup gcc/libgccjit. ​ >\- How do I Native Comp an .el file? Byte-Compile as usual?? You shouldn't need to do anything other than trigger byte-compilation. Assuming you haven't disabled the feature, Emacs will asynchronously natively compile an ELN once a given ELC has been successfully created.
mplscorwin · 2022-04-14 20:07
You should be able to use [process explorer](https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer) to verify that the ELN files provided are being loaded.
mplscorwin · 2022-04-14 20:08
Doesn't work is partially correct, IMO. With the official dist we can load ELN files but not create new ones.
mplscorwin · 2022-04-14 20:33
The GNU distributed versions have native comp enabled (so they can load ELN files) but do not include gcc or libgccgit. For each official release I make I also put a full AOT version on my own site: [corwin.bru.st/emacs-28](https://corwin.bru.st/emacs-28)
mplscorwin · 2022-04-14 20:41
>some (all?) elisp files in the source distribution I believe we get ELN files for all sources that are being byte compiled, so not quite all elisp files in the distribution, but nearly so. You are quite correct that the official bin dists for Windows don't enable AOT. I do make an AOT set also after each successful 'offical' build. They are on [my personal site](https://corwin.bru.st/emacs-28), along with my very messy scripting to accomplish all this.
JohnDoe365 · 2022-04-14 21:20
I have git bash, added the emacs bin directory to .profile and call runemacs. Whenever I open a Emacs package for the first time or a package-list-packages swaps in some updates I see packages being compiled and put into the eln-cache dorectory. Gnu assembler as is run in the background which comes with git bash. I didn't install anything and actually I wonder where libgccjit is coming, is it delivered with Emacs? I am using pre-built 29.0 version.
7890yuiop · 2022-04-14 21:57
> Does it just speed up load time, or is there performance improvement even after it's been loaded? It's a run-time improvement; it isn't intended to benefit load times at all. I assume it slows down load times very slightly in most cases (or if you have a bad time with anti-virus software it could slow down load times a great deal); and if (re)compilation is needed then your machine will also work quite hard for a little bit in the background (asynchronously) on those occasions.
mplscorwin · 2022-04-14 22:10
Where are you getting your pre-compiled binaries? I can say with confidence `libgccjit` is **not** distributed with any prebuilt Emacs binaries distributed via GNU FTP sites. Is it possible you have libgccjit on your path somewhere? You can use [process explorer](https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer) (free from Microsoft) to check for sure where that libgccjit is being loaded and where it is located on your system.
mplscorwin · 2022-04-14 22:12
PS, I wish I'd seen this reply before I wrote up mine. Your answer is great.
ElCondorHerido · 2022-04-15 02:48
Wsl2 is the emacs way for Windows users
JohnDoe365 · 2022-04-15 04:58
I get mine from [https://github.com/kiennq/emacs-build/releases](https://github.com/kiennq/emacs-build/releases) and inspecting /emacs/bin reveals that gcc comes with it. I can confirm that native compilation works flawless with this builds.
[deleted] · 2022-04-15 05:32
>AOT version Super helpful. Thank you.
[deleted] · 2022-04-15 05:43
How does this affect packages installed manually by the user. Are these byte compiled automatically?
mplscorwin · 2022-04-15 05:43
Cool, I'll try those out; thanks much. Emacs dev team doesn't want to include full sources for GCC in the release tarballs is why that's not an option 'upstream' IIUC.
mplscorwin · 2022-04-15 05:59
Depends on how you install packages, I guess. The default method (using `package.el`) includes byte-compilation during install (which then triggers native compilation where available).
[deleted] · 2022-04-15 06:18
I do not use package.el or any package manager. So I guess I would have to byte-compile myself.
ndamee · 2022-04-15 06:28
But why are the lisp files not natively compiled in the distribution? It would make the life of users easier.
telenieko · 2022-04-15 08:57
As far as I saw, everything in the distribution gets compiled for the first time when you start emacs with libgccjit available. I guess shipping it precompiled could make things harder on the distribution side given how many versions of Windows are out there and maybe different architectures
mplscorwin · 2022-04-15 15:07
Gotcha. You might check out this package if you want to automate byte-compilation. [https://github.com/emacscollective/auto-compile](https://github.com/emacscollective/auto-compile)
ndamee · 2022-04-15 15:57
There are already some precompiled binary elisp files in the distribution, so different Windows versions don't matter. The emacs executable itself is a binary which runs on various Windows versions, after all. So if this is the case then all elisp files could be shipped precompiled to native.