-
Notifications
You must be signed in to change notification settings - Fork 4.6k
chore: optimise first evaluation by adding worker scope cache (CE) #38068
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ff3018c
chore: optimise first evaluation using scope cache
541a00f
add feature flag integration
f7bdef4
fix a return statement in getDataTree context
70955ef
remove default export of evaluateSync fn
a6b86de
set cachedScope only if the ff is enabled
6203160
Fix test cases
5c933fb
resolve pr comments
7ed4dc3
use only one evalContextCache
294eb99
Merge remote-tracking branch 'origin' into chore/first-eval-optimisat…
9a7150f
Merge remote-tracking branch 'origin' into chore/first-eval-optimisat…
9d770d9
use klonaJSON instead of klona
04b1e85
use set instead of array for actionNames
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { GracefulWorkerService } from "./WorkerUtil"; | ||
|
|
||
| export const evalWorker = new GracefulWorkerService( | ||
| new Worker( | ||
| new URL("../workers/Evaluation/evaluation.worker.ts", import.meta.url), | ||
| { | ||
| type: "module", | ||
| // Note: the `Worker` part of the name is slightly important – LinkRelPreload_spec.js | ||
| // relies on it to find workers in the list of all requests. | ||
| name: "evalWorker", | ||
| }, | ||
| ), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,7 @@ import { | |||||
| PrimitiveErrorModifier, | ||||||
| TypeErrorModifier, | ||||||
| } from "./errorModifier"; | ||||||
| import { addDataTreeToContext } from "ee/workers/Evaluation/Actions"; | ||||||
| import { getDataTreeContext } from "ee/workers/Evaluation/Actions"; | ||||||
| import { set } from "lodash"; | ||||||
| import { klona } from "klona"; | ||||||
| import { getEntityNameAndPropertyPath } from "ee/workers/Evaluation/evaluationUtils"; | ||||||
|
|
@@ -103,7 +103,7 @@ const ignoreGlobalObjectKeys = new Set([ | |||||
| "location", | ||||||
| ]); | ||||||
|
|
||||||
| function resetWorkerGlobalScope() { | ||||||
| export function resetWorkerGlobalScope() { | ||||||
| const jsLibraryAccessorSet = JSLibraryAccessor.getSet(); | ||||||
|
|
||||||
| for (const key of Object.keys(self)) { | ||||||
|
|
@@ -273,14 +273,15 @@ export const createEvaluationContext = (args: createEvaluationContextArgs) => { | |||||
| Object.assign(EVAL_CONTEXT, context.globalContext); | ||||||
| } | ||||||
|
|
||||||
| addDataTreeToContext({ | ||||||
| EVAL_CONTEXT, | ||||||
| const dataTreeContext = getDataTreeContext({ | ||||||
| dataTree, | ||||||
| configTree, | ||||||
| removeEntityFunctions: !!removeEntityFunctions, | ||||||
| isTriggerBased, | ||||||
| }); | ||||||
|
|
||||||
| Object.assign(EVAL_CONTEXT, dataTreeContext); | ||||||
|
|
||||||
| overrideEvalContext(EVAL_CONTEXT, context?.overrideContext); | ||||||
|
|
||||||
| return EVAL_CONTEXT; | ||||||
|
|
@@ -373,7 +374,8 @@ export default function evaluateSync( | |||||
| // TODO: Fix this the next time the file is edited | ||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||
| evalArguments?: Array<any>, | ||||||
| configTree?: ConfigTree, | ||||||
| configTree: ConfigTree = {}, | ||||||
| scopeCache?: EvalContext, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we name the variable to be able to explain it's usecase.
Suggested change
|
||||||
| ): EvalResult { | ||||||
| return (function () { | ||||||
| const errors: EvaluationError[] = []; | ||||||
|
|
@@ -394,16 +396,34 @@ export default function evaluateSync( | |||||
| }; | ||||||
| } | ||||||
|
|
||||||
| resetWorkerGlobalScope(); | ||||||
| self["$isDataField"] = true; | ||||||
| const EVAL_CONTEXT: EvalContext = {}; | ||||||
|
|
||||||
| setEvalContext({ | ||||||
| dataTree, | ||||||
| configTree, | ||||||
| isDataField: true, | ||||||
| isTriggerBased: isJSCollection, | ||||||
| context, | ||||||
| evalArguments, | ||||||
| }); | ||||||
| ///// Adding callback data | ||||||
| EVAL_CONTEXT.ARGUMENTS = evalArguments; | ||||||
| //// Adding contextual data not part of data tree | ||||||
| EVAL_CONTEXT.THIS_CONTEXT = context?.thisContext || {}; | ||||||
|
|
||||||
| if (context?.globalContext) { | ||||||
| Object.assign(EVAL_CONTEXT, context.globalContext); | ||||||
| } | ||||||
|
|
||||||
| if (scopeCache) { | ||||||
| Object.assign(EVAL_CONTEXT, scopeCache); | ||||||
| } else { | ||||||
| const dataTreeContext = getDataTreeContext({ | ||||||
| dataTree, | ||||||
| configTree, | ||||||
| removeEntityFunctions: false, | ||||||
| isTriggerBased: isJSCollection, | ||||||
| }); | ||||||
|
|
||||||
| Object.assign(EVAL_CONTEXT, dataTreeContext); | ||||||
| } | ||||||
|
|
||||||
| overrideEvalContext(EVAL_CONTEXT, context?.overrideContext); | ||||||
|
|
||||||
| Object.assign(self, EVAL_CONTEXT); | ||||||
|
|
||||||
| try { | ||||||
| result = indirectEval(script); | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Move this to the
postEvalActionDispatcherdefinition and add comments.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.
waiting on this to be moved