From 064be227bfc5948a74e034fd613d556a49e8b49b Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Fri, 30 Sep 2016 20:17:14 -0700 Subject: Optimize RunCommand by removing /bin/sh wrapper when possible For every $(shell echo "test: $PATH") command, when SHELL is /bin/bash, we essentially run: (each arg wrapped in []) [/bin/sh] [-c] [/bin/bash -c "echo \"test: \$PATH\""] This is redundant, since we can just use SHELL, and then we don't need to do an extra level of shell escaping either. This change makes us run this instead: [/bin/bash] [-c] [echo "test: $PATH"] If SHELL is more complicated than an absolute path to a binary, then we'll fall back to /bin/sh. Using the benchmark introduced in the last change, this reduces a minimal RunCommand execution with a simple SHELL from 3.7ms to 1.3ms. For a more complex benchmark (though less normalized), for an AOSP Android build, this change shrinks the average time spent in $(shell) functions from 4.5ms to 3ms. Change-Id: I622116e33565e58bb123ee9e9bdd302616a6609c --- ninja.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'ninja.cc') diff --git a/ninja.cc b/ninja.cc index 90fe404..e2bc9cd 100644 --- a/ninja.cc +++ b/ninja.cc @@ -737,6 +737,7 @@ class NinjaGenerator { DumpInt(fp, crs.size()); for (CommandResult* cr : crs) { DumpString(fp, cr->shell); + DumpString(fp, cr->shellflag); DumpString(fp, cr->cmd); DumpString(fp, cr->result); if (!cr->find.get()) { -- cgit v1.2.3