BrowserWorks / Waterfox

The official Waterfox 💧 source code repository
https://www.waterfox.net
Other
3.61k stars 333 forks source link

PGO With Clang on Linux Working, WIP Patch Included #855

Closed ilikenwf closed 5 years ago

ilikenwf commented 5 years ago

I have been playing with this off and on for a long time now and finally have it building properly in conjunction with updates made by the Waterfox team and Mozilla upstream, all in an Arch PKGBUILD.

You'll notice in the linked patch below that there are some hacky places, like using /tmp to store our profdata, this was done for the sake of my own expedience and because I'm not aware of all the build system variables - if we put the profdata in the obj output directory, it would get blown away before we build the final browser.

The only caveats I'm aware of right now is that some cflags and ldflags can conflict with PGO, however the hardening and ricing ones in my mozconfig for the repo I'm linking works fine.

The only other changes required out of the ordinary are enabling tests (disabled by default), and adding this to your mozconfig: mk_add_options PROFILE_GEN_SCRIPT='EXTRA_TEST_ARGS=10 $(MAKE) -C $(MOZ_OBJDIR) pgo-profile-run

Then, your build step is this instead of the usual, building from a console inside an X session: make -j -f client.mk profiledbuild

Going forward other than cleanup to make it more proper in places, I wonder how possible it would be to provide an alternative profile location, so that the tests are run in a more realistic scenario instead of a very lean clean fresh profile? Loading up extensions and such, as profiled statistics go, would help with initial load and theoretically with the webrequest related addons like uMatrix and uBlock Origin.

The patch that gets it to build past the last mile: https://aur.archlinux.org/cgit/aur.git/tree/clang-profile.patch?h=waterfox-git

The PKGBUILD repo: https://aur.archlinux.org/cgit/aur.git/tree/?h=waterfox-git

ilikenwf commented 5 years ago

And in a nutshell, PGO uses statis to generate a profile that clang uses in the second, final build, to reorder functions and generally make things even faster and more efficient.

grahamperrin commented 5 years ago

Interesting! Thanks.

https://en.wikipedia.org/wiki/Profile-guided_optimization

… runtime performance …

ilikenwf commented 5 years ago

Thanks - in theory it should improve performance. I believe mozilla supports it, at least, using gcc, but clang does it better in my opinion.

Beyond that I may adjust it to look, and if a profile is in /tmp or an env var is set, it just uses that profile for testing instead.

ilikenwf commented 5 years ago

...also because there's already a flag for it, since Mozilla supports it for gcc, I guess I should sort out some of the env vars and pull request?

ilikenwf commented 5 years ago

This is now broken again after recent updates, we puke when we try to execute one of the .build files in the testing directory.

It looks like upstream firefox may finally have LTO support for clang, though, so I may go without until we have that official support added?

ilikenwf commented 5 years ago

This is no longer applicable for the next milestone, closing, as it should already be included anyway by the mozilla implementation.