5

I'm using ack (sometimes distributed as ack-grep) to search through a complex directory of code, images, who knows what else, and it's reacting pretty slowly. How can I diagnose what it is searching through that is making it slow, so that I can have it ignore 'em?

I just realized that the reasons that my ack-grep are slow will probably make grep slow for the same reason, so I've changed the wording of the title to refer to both.

Current ack-grep command alias:

function view ()
{
echo "ack-grep -i $@ // ignoring third-party directories"
ack-grep -i --ignore-dir=third-party --ignore-dir="unclean-files" --ignore-dir=FCKeditor --ignore-dir=smarty --ignore-dir=codepress --ignore-dir=yui "$@"
}

So I do a case-insensitive search on some string via that alias, e.g. view "Oops! Required fields", ignoring certain directories.

I guess what I could really use is a "verbose" mode to either grep or ack-grep, so that I can visually see subdirectories that it hangs around on because they're slow to search.

Kzqai
  • 22,588
  • 25
  • 105
  • 137

2 Answers2

5

Ended up using the -L switch to make it output all the files that it matches, for quick visual diagnosis of problems. Used just the command structure below:

ack-grep -L "Oops! Required fields were not all completed."

Kzqai
  • 22,588
  • 25
  • 105
  • 137
  • Perfect! @tjameson's answer is useful, but you should change this to be the accepted one. – Tom May 25 '11 at 23:23
  • Nah, tjameson could use the rep more than I (I don't actually know if changing the accepted answer makes a difference at this point). – Kzqai May 26 '11 at 15:39
  • It's not about rep, it's about it being the best answer for other people who have the same issue... – Tom May 29 '11 at 10:45
1

What are you searching for? If it's just source of a particular type (say you're looking for a variable), use the appropriate switch (for perl, use --perl, etc). If you have tons of source, it's gonna take a while regardless of what you do.

Ack-grep is only as smart as you tell it to be. Also, how complex is your regex? Regex has overhead, and if you're just searching for a name of something, don't use regex. You shouldn't use a hammer to loosen a bolt.

beatgammit
  • 19,817
  • 19
  • 86
  • 129
  • Text of any kind, mainly. php source, html, javascript, text files. There are various directories of text files that could potentially be the chokepoint in searches in the specific directory that I'm working in these days, I want to figure out which ones are slowest, see if I can ignore them, and ignore them, so that subsequent searches are fast. I'll add the current command that I'm using to the question. – Kzqai Apr 05 '11 at 18:20
  • Try running time. `time ack-grep ...` outside of your function and optimize from there. – beatgammit Apr 05 '11 at 18:27
  • Hmmm, that is do-able, but I guess what I could really use is a "verbose" mode to either grep or ack-grep, so that I can visually see subdirectories that it hangs around on because they're slow to search. Any ideas? – Kzqai Apr 05 '11 at 18:31
  • Try writing a bash script that calls ack-grep on each directory, outputting the directory and time spend on each directory. Use `-n` or `--no-recurse` to turn off recursion and handle it yourself in the script. – beatgammit Apr 05 '11 at 18:33
  • Hmmm, actually, I can visually verify it's behavior by using the -L switch, that seems to work somewhat (outputs all non-matching files, so you can kinda see what it is slowing down on) – Kzqai Apr 05 '11 at 18:40