Fork me on GitHub

This is nothing super critical but I’ve always wondered: why do certain, say, (defn …)’s show as “white”/in use when they are in fact unused? It seems that if the name of the defn is short, then it actually doesn’t autodetect used/unused.


Yes, your guess is correct. Basically, this inspection is a best effort - if it says that something it’s unused, then it’s unused, but if it doesn’t it still might be unused. This is because checking references is an expensive operation.


So the way this works is that under the hood IntelliJ breaks files down into words, and it has a very fast word search. Generally something like Find Usages will search for all the instances of the word of the name of something, then will check to see if that word is in a string or a comment, and if not it will try to resolve each one to see which are actually references to the thing you’re looking for. This is why a lot of operations are much more expensive for things with short common names.


In this case, the inspection has a hard-coded limit (10 IIRC) - if the word appears more than that number of times, we don’t even bother trying to check references since it would slow everything down too much.


The moral of the story is, don’t call your functions things like ns, let, or whatever 🙂


Understood, thank you for the detailed explanation!


Does that also apply to (:require [… :as alias1]) ? (I assume, yes)


Do you know if there’s a way to tune that from the user perspective to make the search “more accurate”, potentially at the cost of performance? (I am generally pretty happy with the perf. when using a good laptop and charging it)


No, there’s no tweakable knob there sorry, I’m using parameters recommended by JetBrains. I’m hesitant to add a config for that since people could inadvertently break the performance of their IDE for non-obvious reasons.

👍 3

Actually, maybe not…


this is interesting, I made a different try that cause it to mark as unused:


seems like it also cares about the tokenized words, if there are small words between tokens, its the same as a full small name


on a bit more testing, seems like if "every word" is small, the problem remains, but one part of the symbol is a longer word, them it detects unused


Yes, it happens frequently enough but I can’t spot a pattern.