When trying to work with >100k jobs, producing the build script took more than 20 minutes. I don't have proper performance data, but I noticed that ninja_syntax.Writer._line tries to construct a wrapped line with lots of string search within nested loops. As some of my jobs had thousands of dependencies (thereby yielding a string with thousands of spaces), a lot of time will be spent on this code.
This code should not iterate over the text more than once (perhaps by just processing character-by-character from left to right), or else this code should be made optional.
PS.: _count_dollars_before_index could likely be replaced by Python's string.count(), if it remains necessary at all.