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

Recommend using Ninja to build fcitx5-mcbopomofo #96

Open
xatier opened this issue Dec 11, 2023 · 6 comments
Open

Recommend using Ninja to build fcitx5-mcbopomofo #96

xatier opened this issue Dec 11, 2023 · 6 comments

Comments

@xatier
Copy link
Contributor

xatier commented Dec 11, 2023

I wonder if we would like to recommend using ninja to build the project.

To enable ninja, simply add -G Ninja to the CMake command.

cmake ../ -G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DENABLE_CLANG_TIDY=On
cmake --build .
# or just `ninja`

I observed a ~2x boost on my system ( Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz)

# ninja uses $(nproc) +2 jobs by default
$ nproc 
16

$ time ninja
[40/40] Linking CXX shared module src/mcbopomofo.so

real    0m22.833s
user    2m46.923s
sys     0m4.956s
$ time make -j 18
...
[100%] Built target mcbopomofo

real    0m48.043s
user    2m9.943s
sys     0m4.526s
@xatier
Copy link
Contributor Author

xatier commented Dec 21, 2023

One can create CMakeUserPresets.json file with cmake presets

CMakeUserPresets.json:

{
    "version": 8,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 28,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "release",
            "displayName": "Release",
            "description": "Release build with Ninja",
            "generator": "Ninja",
            "binaryDir": "${sourceDir}/build/",
            "cacheVariables": {
                "CMAKE_INSTALL_PREFIX": "/usr",
                "CMAKE_BUILD_TYPE": "Release",
                "ENABLE_CLANG_TIDY": "On"
            }
        },
        {
            "name": "debug",
            "displayName": "Debug",
            "description": "Debug build with Ninja",
            "generator": "Ninja",
            "binaryDir": "${sourceDir}/build/",
            "cacheVariables": {
                "CMAKE_INSTALL_PREFIX": "/usr",
                "CMAKE_BUILD_TYPE": "Debug",
                "ENABLE_CLANG_TIDY": "On"
            }
        }
    ]
}

This will simplify the commands for developers:

$ cmake ../ --preset release
$ ninja

$ cmake ../ --preset debug
ninja && ninja test

@lukhnos
Copy link
Collaborator

lukhnos commented Nov 12, 2024

Revisiting this issue. This is where I feel I don't know enough about making this recommendation. What could be the impact to places that build fcitx5-mcbopomofo automatically, for example the current CI and other package managers that build it from source? How prevalent can we expect to find ninja installed on someone's machine these days?

2x is a good win although this is a small project. What do you think if we provide the ninja- prefixed presets and recommend it in the wiki?

@xatier
Copy link
Contributor Author

xatier commented Nov 12, 2024

If we are talking about C++ projects, I know that big projects such as LLVM and chromium are using Ninja. It should also be easily found in many modern systems [1].

I have no problem with having these instructions in the wiki as an alternative instead of putting in the repo, if we do not feel familiar with the tool.

[1] https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages

@xatier
Copy link
Contributor Author

xatier commented Nov 12, 2024

FYI, just did some builds on my new system (AMD Ryzen 9 9900X 12-Core Processor), still getting ~2x, but I guess that didn't make much difference :p

$ nproc
24

$ time ninja
[54/54] Linking CXX executable src/Engine/gramambular2/gramambular2_test

real    0m3.488s
user    0m45.746s
sys     0m1.505s

$ time make -j 26

real    0m6.126s
user    0m32.843s
sys     0m1.316s

@tianjianjiang
Copy link
Member

@xatier +CC @lukhnos For testing parallel execution of make or ninja, I recommend opening a PR and running them in a VM of GitHub Action,
not only for

the current CI and other package managers that build it from source? How prevalent can we expect to find ninja installed on someone's machine these days?

but also for checking nproc behavior and different amounts of jobs.

The main reason I'd like to know nproc behavior and job amounts is that, nproc doesn't always get the actually available number of CPU cores in a VM, and I also find ninja's "+2" approach strange. Even if the "+2" approach is the best for ninja, it can be bad for make.

xatier added a commit to xatier/fcitx5-mcbopomofo that referenced this issue Nov 13, 2024
@xatier
Copy link
Contributor Author

xatier commented Nov 13, 2024

It won't make much difference on GitHub's CI, they are weak VMs with small # of cores. [1]

I'm not sure if there are any reasons behind the + 2 approach, but here's the code if you're interested:
https://github.com/ninja-build/ninja/blob/master/src/ninja.cc#L256

Here are the numbers if you're interested: https://github.com/xatier/fcitx5-mcbopomofo/actions/runs/11823414619

[1] https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants