Add parser and validation cache - #950
hugo-vrijswijk wants to merge 1 commit into
Conversation
Split `QueryCompiler.compile` into `prepare` (parsing and document-level validation, depends only on document text and schema) and `compilePrepared` (variable coercion, directive validation, elaboration, depends on the per-request `Env`). Add `CachingQueryCompiler` and `QueryCache`, which cache the `prepare` result by document text, including parse failures. Default: 1024 documents, one-hour TTL, LRU eviction. Both are configurable, and callers can supply their own `QueryCache`. Add docs for setup and configuration.
a97019b to
e1425f7
Compare
milessabin
left a comment
There was a problem hiding this comment.
I'm happy with the general idea, but I think the implementation here is too specific. Maybe move the concrete implementation out of core? It should be possible to back the cache with caffeine on the JVM, for instance, or Redis.
Also, using the raw document text as a cache key is problematic IME. Normalizing it first (ie. running it through the minimzer) and hashing is a better bet.
But I think this all belongs in separate, or even external modules ... there are many different choices you might make.
|
Good points, I initially leaned towards a serializable format too. But because of all the references to the schema and validations. The validation results could be dropped, but that is quite a large part of what is cached in this PR. Actual pluggable remote caches would be a big win. For normalization, I agree this would be great. But the (current) I think different cache hits on different whitespace is fine. The cost is just a single reparse per document, and most applications will be built to send the same documents in most cases. What we could do instead is only cache the parsed AST result as long as it is a For a separate module, do you mean the in-memory implementation to be separate? Or the caching interface? Something like |
Split
QueryCompiler.compileintoprepare(parsing and document-level validation, depends only on document text and schema) andcompilePrepared(variable coercion, directive validation, elaboration, depends on the per-requestEnv).Add
CachingQueryCompilerandQueryCache, which cache theprepareresult by document text, including parse failures. Default: 1024 documents, one-hour TTL, LRU eviction. Both are configurable, and callers can supply their ownQueryCache.Add docs for setup and configuration.