-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
ReflectionCache takes a lot of memory #584
Comments
I don't maintain this module, but one thing to also consider -- a simpler question -- is whether the default size -- 100,000?!?! -- is way too big. But I am also surprised that anything would use One challenge here is that this module does not currently have an active maintainer it seems. We have had active maintainers occasionally but time to spend on OSS varies. So while we'd welcome PRs, I am also not sure who could actually review it. But FWTW, I'd be happy to merge a patch to reduce default sizes at very least; and that could go in |
Hi @cowtowncoder , Thanks for your swift reply. The cache size defaults to 512 entries. Even if we reduce this, a few entries can still accumulate a lot of classes. At least it's possible to configure this value when instantiating the module and disable the cache with a zero value. But like you said I don't know the consequences performance side. |
@jcsdt Ok I must have misread the stats here. 512 sounds ok. I do like your idea of configurable size, including 0 to disable. So I think as the first step, configurable size contribution would be well received. |
I worked on reducing cache space in #627 and #628. I have the following other ideas.
The rationale for the idea is that the overall processing results are cached on the However, I believe that micro-benchmark performance validation is essential for these changes (as well as for |
@jcsdt First, there appears to be a problem with the implementation of Also, it looks like At least the former is easy to fix and I will create a PR soon. |
Some of the measures related to this issue will be published in |
@jcsdt |
The corrections to the areas raised as an issue have been completed and will be closed. |
Hello,
We noticed on one of our production system that the ReflectionCache retains indirectly a lot of classes which adds up to a lot of memory.
In our case, after a full GC, we still have close to 2 millions
kotlin.reflect.jvm.internal.impl.metadata.ProtoBuf$Type
along with other internal kotlin reflect classes taking close to 1 GB on the heap.Analysing a heap dump, the culprit seems to be javaConstructorToValueCreator which by retaining a list of
KParameter
indirectly retainskotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassConstructorDescriptor
which in turns has a lot of references to other classes.I'm not knowledgeable enough with kotlin reflection to suggest a solution there. But we could wrap the values of all the maps inside ReflectionCache with
SoftReference
to let the GC collect them when needed.Happy to submit a PR if you agree with this solution.
Thank you
Versions
Kotlin: 1.5.31
Jackson-module-kotlin: 2.13.3
Jackson-databind: 2.13.3
Additional context
I link a screenshot of Eclipse Memory Analyzer which show the merged shortest path excluding any soft/weak references.
The text was updated successfully, but these errors were encountered: