needle icon indicating copy to clipboard operation
needle copied to clipboard

Generator directory traversal speed is slow

Open brentleyjones opened this issue 6 years ago • 0 comments

First, thank you for the wonderful DI framework!


I've found that just traversing the input directory is quite slow. To prove this, I ran the following command, which excluded all files it came across (because the project is in a directory called Development... which seems like a bug since exclusion paths should only consider paths from the working directory 🤷‍♂):

time Carthage/Checkouts/Needle/Generator/bin/needle generate App/Sources/Generated/Needle.swift . --exclude-paths /Development/

The output for our current project, which has about 8600 files, is about a second.

When only excluding what we need to the time is around 4 seconds.


I know this can be faster, since for the time being we are instead invoking ag (https://github.com/ggreer/the_silver_searcher) to find all files with import NeedleFoundation and then using those files as the input:

time ag --depth -1 --group -l "import NeedleFoundation" > App/Sources/Generated/NeedleSourceList.txt

This takes about 0.25 seconds and then the following takes about 0.08 seconds (since the source list is only 8 files):

time Carthage/Checkouts/Needle/Generator/bin/needle generate App/Sources/Generated/Needle.swift App/Sources/Generated/NeedleSourceList.txt

In summary, by using an external program to generate the source file list we make the generation process at least an order of magnitude faster.

brentleyjones avatar Oct 10 '19 13:10 brentleyjones