Store annotation getters of ClassInfo and MethodInfo by freya022 · Pull Request #878 · classgraph/classgraph

@freya022 Thanks for the contribution! I didn't realize these same methods would be called repeatedly on the same classes, so I never cached them. Are you duplicating work in your code?

There are probably some other method calls that could be memoized in this way too, but I don't have the time to review/audit the API surface right now.

The downside of this is of course greater memory overhead while the ScanResult is still in scope and not closed. People already complain about ScanResult producing an enormous object graph that can cause OOM on low-memory systems. But since you got such a big speedup from this change, it is probably worth it to cache this.