Caching PsiElements?

Hi all,

I'm working on a performance problem with symbol resolution in the Clojure plugin. The problem seems to be that every time it resolves a symbol it reparses the entire standard library. I've replaced that call with one that caches the returned PsiElements - is this allowed? They come from a file that does not change, but I'm guessing that if the user navigates to that file, for example, it may be reparsed and new PsiElements created. What would be the best solution to this problem? Is there a way to check if the PsiElements I have cached are still valid?

Thanks,
Colin

3 comments
Comment actions Permalink

Storing PSI elements from a file that doesn't change is generally OK. The file will only be reparsed if its contents changes; if you want to make sure that your cache survives a reparse, you can use SmartPsiElementPointer instances instead of storing PSI elements directly. Otherwise, simply check PsiElement.isValid() and find the element again if it returned false.

0
Comment actions Permalink

Perfect, thanks Dmitry!

0
Comment actions Permalink

Actually, another approach I was thinking of taking with this was to use a stub index. I'm assuming the stub indexes are one-many? So I could create an index from namespace name to symbol, and add to it all symbols that are public in that namespace? Would that be preferable to the caching idea?

0

Please sign in to leave a comment.