Commit graph

9 commits

Author SHA1 Message Date
Cole Faust
c5baf11a2d Show the ninja string that failed to parse in errors
So that it's easier to debug what the problem is.

Test: m nothing
Change-Id: I97e81f98f0365e981d34c6b8bec8528de1b7e514
2023-01-19 14:23:04 -08:00
Colin Cross
2ce594e446 Make ninjaString an interface
There are 8935901 *ninjaString objects generated in an AOSP
aosp_blueline-userdebug build, and 7865180 of those are a literal
string with no ninja variables.
Each of those *ninjaString objects takes a minimum of 48 bytes for
2 slices, plus 8 bytes for the pointer to the ninjaString.  For
the literal string case, one of those slices has a single element,
(costing another 16 bytes for the backing array), and the other
slice is empty, for a total of 72 bytes.

Replace *ninjaString with a ninjaString interface.  This increases
the size of the reference from 8 bytes to 16 bytes, but using
a type alias of a string for the literal string implementation uses
only 16 bytes, saving 40 bytes per literal string or 314 MB.

Test: ninja_strings_test
Change-Id: Ic5fe16ed1f2a244fe6a8ccdf762919634d825cbe
2020-01-29 16:23:40 -08:00
Colin Cross
19ff727ad5 Optimize ninjaString.ValueWithEscaper
ninjaString.ValueWithEscaper is a relatively hot function,
rewrite it with strings.Builder to avoid repeated string
concatenation, which requires an allocation each time.

Before:
BenchmarkNinjaString_Value/constant/1-72       	100000000	        11.9 ns/op
BenchmarkNinjaString_Value/constant/10-72      	100000000	        18.9 ns/op
BenchmarkNinjaString_Value/constant/100-72     	50000000	        22.1 ns/op
BenchmarkNinjaString_Value/constant/1000-72    	30000000	        39.3 ns/op
BenchmarkNinjaString_Value/variable/1-72       	20000000	        95.1 ns/op
BenchmarkNinjaString_Value/variable/10-72      	10000000	       223 ns/op
BenchmarkNinjaString_Value/variable/100-72     	 3000000	       437 ns/op
BenchmarkNinjaString_Value/variable/1000-72    	 2000000	       948 ns/op
BenchmarkNinjaString_Value/variables/1-72      	10000000	       161 ns/op
BenchmarkNinjaString_Value/variables/2-72      	 5000000	       368 ns/op
BenchmarkNinjaString_Value/variables/3-72      	 3000000	       560 ns/op
BenchmarkNinjaString_Value/variables/4-72      	 2000000	       795 ns/op
BenchmarkNinjaString_Value/variables/5-72      	 1000000	      1004 ns/op
BenchmarkNinjaString_Value/variables/10-72     	 1000000	      2275 ns/op
BenchmarkNinjaString_Value/variables/100-72    	   50000	     39667 ns/op
BenchmarkNinjaString_Value/variables/1000-72   	    1000	   2146592 ns/op

After:
BenchmarkNinjaString_Value/constant/1-72       	200000000	        11.3 ns/op
BenchmarkNinjaString_Value/constant/10-72      	100000000	        17.2 ns/op
BenchmarkNinjaString_Value/constant/100-72     	50000000	        21.7 ns/op
BenchmarkNinjaString_Value/constant/1000-72    	30000000	        38.3 ns/op
BenchmarkNinjaString_Value/variable/1-72       	20000000	        91.8 ns/op
BenchmarkNinjaString_Value/variable/10-72      	10000000	       199 ns/op
BenchmarkNinjaString_Value/variable/100-72     	 5000000	       377 ns/op
BenchmarkNinjaString_Value/variable/1000-72    	 2000000	       855 ns/op
BenchmarkNinjaString_Value/variables/1-72      	10000000	       141 ns/op
BenchmarkNinjaString_Value/variables/2-72      	 5000000	       312 ns/op
BenchmarkNinjaString_Value/variables/3-72      	 5000000	       362 ns/op
BenchmarkNinjaString_Value/variables/4-72      	 3000000	       417 ns/op
BenchmarkNinjaString_Value/variables/5-72      	 2000000	       621 ns/op
BenchmarkNinjaString_Value/variables/10-72     	 2000000	       837 ns/op
BenchmarkNinjaString_Value/variables/100-72    	  200000	      9141 ns/op
BenchmarkNinjaString_Value/variables/1000-72   	   20000	     95094 ns/op

Test: ninja_strings_test.go
Change-Id: I6c61e747d8e67f7f1e6cff0cc0c705745301a35f
2019-06-20 11:05:58 -07:00
Colin Cross
8de48af6de Escape leading space in ninja strings
Spaces normally don't need to be escaped, but leading spaces are
trimmed.  Escape leading space to allow setting a variable to a
value with leading spaces.

Test: ninja_string_test.go
Change-Id: Ic0ffb076dbd603b7c0203720b9c1ea635c5ded75
2017-05-09 10:14:38 -07:00
Colin Cross
63d5d4d9e4 Fix formatting
gofmt -w .

Change-Id: If9cf0b7bd810f899edffcd2edf361fa83245bd2a
2015-04-20 16:41:55 -07:00
Colin Cross
8c1c6c03f8 Pre-allocate ninjaString slices
Naively pre-allocate ninjaString slices by counting $ characters as
an estimate of how many variables will be needed.  Saves 5% cpu time
on one workload.

Change-Id: Ib3a41df559d728b2db047f6dbbf9eb06d7045303
2015-04-15 11:03:17 -07:00
Colin Cross
b247893deb Fix misparsed $ after variable name
If a $ sign occurs after a variable name, the ninja string parser
fails to check if it is a $$ or a ${.  Go to the
parseDollarStartState instead of the parseDollarState.

Since it is not yet known if the $ is the beginning of a new
variable (${ or $<alphanumeric>) or a string ($$), an empty string
separator cannot be added to the ninjaString strings list.  Instead,
add functions to push strings or variables onto the ninjaString,
and automatically add the blank separator if two variables are
pushed in a row.

Change-Id: Ia1cae6259b1d7e4f633f61b9eadb2a2028bbd5f0
2015-04-14 16:21:53 -07:00
Colin Cross
8e0c51192a Add license headers and LICENSE file
Change-Id: I6f7c7374093c0745ee4aa677480376a06648b358
2015-01-23 14:23:27 -08:00
Colin Cross
3e8e74f276 Move blueprint/* up a directory
Make integrating with go tools easier by putting the blueprint package
files in the top level directory of the git project instead of in a
subdirectory called blueprint.

Change-Id: I35c144c5fe7ddf34e478d0c47c50b2f6c92c2a03
2015-01-23 14:23:27 -08:00
Renamed from blueprint/ninja_strings_test.go (Browse further)