-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[WIP] Expressions caching #51160
[WIP] Expressions caching #51160
Conversation
Pinging @elastic/kibana-app-arch (Team:AppArch) |
💔 Build Failed
|
aea6428
to
f240fd0
Compare
f240fd0
to
dd82b84
Compare
💔 Build Failed
|
💔 Build Failed
|
@@ -37,12 +38,13 @@ export interface InterpreterConfig { | |||
functions: FunctionsRegistry; | |||
types: any; | |||
handlers: any; | |||
functionCache: Map<any, any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functionCache: Map<any, any>; | |
functionCache: Map<string, any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functionCache: Map<string, unknown>;
I don't know if this will work out, but if it does, it is more restrictive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have unit tests for this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly a nit: Can we standardize on a single variable name like disableCache
or enableCache
and use it as the name for both the variable in the function definition and when invoking the interpreter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, maybe there is a way to write this in a more modular way and put the caching logic in some separate place. Otherwise, this interpreterProvider
function is already too long.
handlers.getInitialContext(), | ||
]); | ||
fnOutput = functionCache.get(hash); | ||
if (!fnOutput) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible 0, "", false edge case?
I'd use functionCache.has(hash)
to check if there is a cache hit
are you fine for leaving it as is for now, you plan to refactor interpreterProvider anyway ? |
dd82b84
to
e875a92
Compare
@ppisljar yes in my branch this |
lets merge refactoring first, and lets add caching in separate PR. There is not much of code here so it should not be hard to reimplement in the refactored version. |
e875a92
to
b8a163f
Compare
b8a163f
to
273c3d0
Compare
updated this on top of refactoring. |
273c3d0
to
b142a28
Compare
retest |
4fa5fa9
to
f3a4677
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have disabled caching from some of the functions maintained in expressions
plugin and esaggs
, and tsvb
. But opting in by default all functions into caching behaviour seems to be a breaking change, as I understand it, or no? For example, shall we also opt-out of caching some of Lens and Canvas functions?
src/plugins/expressions/common/expression_functions/expression_function.ts
Outdated
Show resolved
Hide resolved
src/plugins/expressions/common/expression_functions/expression_function.ts
Outdated
Show resolved
Hide resolved
/** | ||
* prevents caching in the current execution. | ||
*/ | ||
disableCache?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we should expose through execution context to all functions? How would functions use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should already be provided to all functions on the executionContext.
if some function would to do some internal caching (esaggs with make it slow) this would indicate that it should do it.
const hash = calculateObjectHash([fn, normalizedInput, args, this.context.search]); | ||
if (!this.context.disableCache && !fn.disableCache && this.functionCache.has(hash)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can first check if we have to cache and only then hash.
const doCaching = !this.context.disableCache && !fn.disableCache;
if (doCaching) {
const hash = calculateObjectHash([fn, normalizedInput, args, this.context.search]);
}
471d951
to
a94e790
Compare
Since we're past 7.11.0 FF, and this isn't a bug fix, should probably bump to 7.12.0. |
@ppisljar This PR is super outdated, did you mean to move it out of draft status or did you want to close it? |
💔 Build Failed
Failed CI StepsMetrics [docs]
History
To update your PR or re-run it, just comment with: |
we implemented request caching on search service which should resolved main needs for which we were thinking about expression caching |
Summary
Adds caching for interpreter:
interpretAst
input
,args
,executionContext
andfnDef
and check the cache for existing result. If we find one we can skip executing this function.disableCache
flag set to true, which will prevent caching of that functionarguments are resolved before this, so using subexpressions, default values etc should work as expected (if subexpression evaluates to the same result it did last time executing the current function can be skipped)
todo:
as timerange which we use in
esaggs
is in estime formatnow-90d
caching kicks in when we rerun same expression at later time and we don't get new result. For nowesaggs
function has thedisableCache
flag set to true. When we refactore esaggs in the future this flag should move to the function that will be generating actual timerange from theestime
formatopen questions:
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.For maintainers