-
Notifications
You must be signed in to change notification settings - Fork 215
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
Should schemas memoize their derived objects? #498
Comments
Definetely. But not just the derived objects but the (= (m/schema :int) (m/schema :int))
; => false ... for any large schema system, that really hogs CPU & memory. If you happen to also use schema transformation utilities such as A bounded cache baked into the core? Something like #236 would make it non-global. related #299 (just closed). |
Ofc, you're right, the schema itself should be cached as well. |
separated schema creation into separate issue, with analysis #513. |
this will be resolved in #550. |
actually, caching decoders & encoders is not trivial: the forms, validators, explainers and parsers are identical per Schema, so easy to cache., |
By derived objects, I mean validator, explainer, de/encoder, etc.
What exists currently:
Let us consider the following simple case:
If we pick apart the decoder object:
What we see here is the transformer functions for each of the keys, x, and y are different objects, while they were derived from the same schema with the same transformer.
If we memoized the decoder they would have been the same object
Why consider this option?
Especially when building big complex schemas, this can potentially improve performance when deriving decoders where multiple references to a schema exist. This translates effectively to faster startup
Another consideration is how the JVM's JIT operates: there is a limit to the JIT's code cache size. By putting more objects and method calls on a potentially hot path, we give the JIT compiler more code to compile, potentially forcing a deoptimization of another method to make room. This can contribute to overall improved performance.
How can we test this and how can we determine viability:
Criteria for acceptance / rejection:
Up to you, really, I just come up with weird ideas.
The text was updated successfully, but these errors were encountered: