Skip to content

ProxyFactory should not discard objenesis cache, thereby enabling efficient proxy instantiation [SPR-12755] #17352

@spring-projects-issues

Description

@spring-projects-issues

Adrian Moos opened SPR-12755 and commented

We are using ProxyFactory to decorate Spring Beans when passing them over an api boundary to give each caller a proxy object of their own.

We have now noticed that proxy creation is quite an expensive process, taking 0.3 ms per proxy object, even though the proxies were all for the same target class in this test.

Analysis with JProfiler yielded the attached screenshot. Apparently, the proxy class is reused, but the objenesis ObjectInstantiator is recreated for every call to getProxy().

The objenesis tutorial recommends:

To improve performance, it is best to reuse the ObjectInstantiator objects as much as possible. For example, if you are instantiating multiple instances of a specific class, do it from the same ObjectInstantiator. Both InstantiatorStrategy and ObjectInstantiator can be shared between multiple threads and used concurrently. They are thread safe.


Affects: 4.1.2

Attachments:

Issue Links:

Referenced from: commits 287045e

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions