-
-
Notifications
You must be signed in to change notification settings - Fork 868
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
Let users configure Cache to use for compiled schemas #2134
Comments
Pull request: #2135 |
Pull request would be useful to accept. This is good practice to use WeakMap for caching purpose rather then plain Maps. In opposite to plain Map, WeakMap does not hold extra references for its keys, so it does not prevent garbage collector to release memory allocated by keys. Of course good practice is to avoid schema object duplication (e.g. single object for single schema). But there are some scenarios where cache is not applicable, for example schema could be variable object with short life time. There are plenty issues caused by Map based cache - #1413 #1879 #1763 #1763. |
Possibly, a better solution to let users configure which cache to use - as it was in the previous versions... The problem with using WeakMap by default is that it would mask the cases of incorrect schema usages, when the same schema is recompiled, eliminating any benefits of the compilation, while a memory leak helped detecting these issues in most cases. Also, for cases where schema is dynamic and used only once (or maybe a few times) using compilation is suboptimal, it is more efficient to simply use interpreting validator... |
@epoberezkin do you mean cache option introduced by 0.7.0?
|
What version of Ajv you are you using?
8.11.0
What problem do you want to solve?
If
compile
function called with same by-value, but not by-ref object, it can cause cache overflow and memory leakage.What do you think is the correct solution to problem?
Implement WeakMap instead of Map class.
Will you be able to implement it?
I'll attach the pull request.
The text was updated successfully, but these errors were encountered: