Skip to content

Potential memory leak in WebMvcLinkBuilder #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
odrotbohm opened this issue Nov 23, 2021 · 0 comments
Closed

Potential memory leak in WebMvcLinkBuilder #1723

odrotbohm opened this issue Nov 23, 2021 · 0 comments
Assignees
Labels
in: core Core parts of the project stack: webmvc type: bug
Milestone

Comments

@odrotbohm
Copy link
Member

Back-port of #1701.

@odrotbohm odrotbohm added type: bug stack: webmvc in: core Core parts of the project labels Nov 23, 2021
@odrotbohm odrotbohm added this to the 1.4.1 milestone Nov 23, 2021
@odrotbohm odrotbohm self-assigned this Nov 23, 2021
odrotbohm added a commit that referenced this issue Nov 23, 2021
We now constrain the cache of controller proxy instances to 256 elements using Spring's ConcurrentLruCache to avoid instances created via DummyInvocationUtils.methodOn(Class<?>, Object…). The parameters are part of the cache key and used to expand the type-level mappings. If those vary for each call and a request creates a lot of links (>100000) the memory consumption grows significantly, first and foremost indefinitely.

Using the ThreadLocal will still make sure that the cache is local to a current request, so the proxies can actually be reused as the method invocations used to record the mappings would interfere for concurrent requests otherwise.

Removed obsolete generic parameter on the CacheKey type.
odrotbohm added a commit that referenced this issue Nov 23, 2021
The commits for #467 significantly degraded performance as CachingMappingDiscoverer.getParams(Method) doesn't properly cache the result of the call which causes quite expensive, unnecessarily repeated annotation lookups for the very same method. We also avoid the creation of an Optional instance for the sole purpose of a simple null check.

Introduce FormatterFactory to potentially cache the to-String formatting functions and thus avoid repeated evaluation and Function object creation.

We now also avoid the creation of ParamRequestCondition instances if no @RequestParams(params = …) values could be found in the first place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project stack: webmvc type: bug
Projects
None yet
Development

No branches or pull requests

1 participant