Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

AdvisingBeanPostProcessor can call excessively AopUtils.canApply which can lead to performance issue when using Spring prototypes #185

Open
matlach opened this issue Jul 19, 2016 · 16 comments

Comments

@matlach
Copy link

matlach commented Jul 19, 2016

Our application heavily rely on the following pattern:

    @Component @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public class Prototype { ... }

    @Inject
    private Provider<Prototype> prototypeProvider;

    public Prototype getPrototype() {
        return prototypeProvider.get();
    }

each time we instantiate the Prototype object, the AdvisingBeanPostProcessor is getting called and eventually test wheter we can apply AOP on that prototype class using AopUtils.canApply(pointcut, targetClass)

The implementation of AopUtils.canApply is really heavy weight, it has to drill down in each available methods of the target class which can then lead to performance issue.

I do not know if there would be any ways to optimize the pattern? My initial thought is just to create a Map to store wheter if for a given pointcut + targetClass if the check has already been done.
WDYT?
Finally, if you think this is the only way, I can provide a pull request with a potential fix.

Thanks,

@ryantenney
Copy link
Owner

Oh interesting, I didn't realize it hit prototype scoped beans so hard. My only concern is the memory usage of that cache. If only Java had a builtin LFU cache. I've pushed a possible fix: https://github.com/ryantenney/metrics-spring/tree/can-apply-cache. Would you be able to test it and see if there's an improvement?

@matlach
Copy link
Author

matlach commented Jul 25, 2016

I should be able to test soon if this resolved our issue.
I'll keep you updated but I'm very confident with your proposed fix.

@matlach
Copy link
Author

matlach commented Jul 26, 2016

We performed a stress test yesterday with your proposed fix an the issue is definitly gone.

@ryantenney
Copy link
Owner

Thanks so much!

@matlach
Copy link
Author

matlach commented Aug 5, 2016

Hi @ryantenney ,
I was just wondering, do you know when this fix will become mainstream in the 3.1.x branch?

Thanks!

@efasel
Copy link

efasel commented Nov 10, 2016

Hi @ryantenney ,
well… I have basically the same question as @matlach: are you planning to release a v3.1.4 with that fix so we can simply update our maven dependencies? Would be awesome!
Thanks a lot!

@efasel
Copy link

efasel commented Jun 19, 2018

Hi @ryantenney , any update on this? Thanks!

@ryantenney
Copy link
Owner

@efasel I'm sorry I haven't gotten this fix out! I'll cut a release this week.

@efasel
Copy link

efasel commented Aug 29, 2018

Hi @ryantenney ! :-)

Two month ago you wrote:

I'm sorry I haven't gotten this fix out! I'll cut a release this week.

Obviously something has come up, but maybe you'll have time soon? Would be great to have a release including this important fix. Thanks!

Best regards,
Elmar

@ryantenney
Copy link
Owner

That was 2 months ago? I'm sorry for keeping you waiting. My personal laptop died and took with it the key I need to sign the release. I'll find a backup and get a release out soon.

@efasel
Copy link

efasel commented Oct 1, 2018

Hi @ryantenney, sorry to hear that your laptop died. I hope you didn't lose anything important.
Any plan to do this release we're talking about soon? :-) Best regards, Elmar

@efasel
Copy link

efasel commented Dec 6, 2018

Hi @ryantenney, what about a nice Christmas present for the community and have a v3.1.4 release? 🎄 🎁 ? 😃 Best regards, Elmar

@ryantenney
Copy link
Owner

I just got my laptop back from Apple yesterday ;) coming right up

@efasel
Copy link

efasel commented Dec 6, 2018

🎉

@efasel
Copy link

efasel commented Jan 18, 2019

Hi @ryantenney ! I just saw that you created a tag for v3.1.4 but this was not released to the usual maven repositories. So – as far as I know – we cannot simply update our dependency:

[WARNING] The POM for com.ryantenney.metrics:metrics-spring:jar:3.1.4 is missing, no dependency information available

Are you planning on pushing v3.1.4 as an official release?

@efasel
Copy link

efasel commented Mar 21, 2019

Hi @ryantenney! How are you today? Just wanted to ask regarding the 3.1.4 release … :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants