Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something in the ninja language that makes it faster than make?

I often see the claim made that Ninja is faster than Make, is better at supporting incremental builds, and better at parallelization. Is this a quality of implementation issue or is there something in the Ninja language that enables this?

I understand that Ninja and Make use different file formats to describe the dependency graph of tasks. I understand that Make allows the use of more high level features, such as globs, than ninja. If such high-level features are used then Make performs a more complex task than Ninja and we cannot expect Make to be faster. This is an unfair comparison.

However, assume that such high level features are not used. No globing, no pattern rules, just basic "out_file: in_file1, in_file2\n\tcommand to build" repeated over and over and over. Not using such high-level feature evens the playing field between Make and Ninja in terms of the task that they perform.

My understanding is that, if we limit Makefiles in such a way, that Ninja files and Makefiles can easily be transformed into each other. Is this correct?

Is there any inherent reason why Make executed on limited Makefiles is any slower than Ninja? or is it simply case of the standard Make implementations not being optimized for Makefiles that are structured in this way?

like image 924
B.S. Avatar asked Jul 11 '20 09:07

B.S.


1 Answers

In short, Ninja parses faster, and has built-in features that reduce the amount to parse.

From the philosophical overview in the ninja manual:

Where other build systems are high-level languages, Ninja aims to be an assembler.

Ninja files are often "compiled" from other makefiles, making it a two-step process whereas Make is a single step. The two-step can be slower than plain Make. Because only the second step is necessary for most the time the net effect is it being faster. It's somewhat similar to comparing a compiled and interpreted program.

Ninja add several features to Make. Implementing these in a makefile lead to longer, more complicated makefiles and thus much more parsing.

like image 195
Andreas Avatar answered Sep 22 '22 21:09

Andreas