Skip to content

Conversation

@freya022
Copy link
Contributor

As those are the most likely used, this could save considerable CPU time

In my workload these changes produce a 2x improvement (~167ms -> ~84ms), as I run over some classes multiple times

@lukehutch
Copy link
Member

@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.

@lukehutch lukehutch merged commit 00cb918 into classgraph:latest Aug 18, 2024
@freya022
Copy link
Contributor Author

freya022 commented Aug 18, 2024

Yes, there are multiple places where i need to check for the annotations, a workaround would be to create my own objects which store the CG object and a few other properties I often need, having the annotations stored on the CG object is cleaner and performant enough

@freya022 freya022 deleted the annotation-info-cache branch August 19, 2024 20:26
@lukehutch
Copy link
Member

Released in 4.8.175. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants