PsiElement getProject performance
Answered
On the page with performance tips it is stated that the getProject() method on a PsiElement runs up the entire PsiTree. However, when I look at the code it appears that the PsiManager it used to obtain the project value. Am I misinterpreting the code or the documentation? Before I start refactoring all my code to use a static Project reference I would like to make sure it makes sense ;)
source: https://plugins.jetbrains.com/docs/intellij/performance.html#avoid-expensive-methods-in-psielement
Please sign in to leave a comment.
See com.intellij.psi.impl.source.tree.TreeElement#getManager.
Never store _static_ Project references anywhere. The idea is to obtain `Project` instance outside of loops or other heavy processing when it's clear it refers to the same instance always.