-
Notifications
You must be signed in to change notification settings - Fork 60
[FIX] Evaluation: Optimize invalidation of cell depending of spreads #6827
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
base: 18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ export class Evaluator { | |
); | ||
private blockedArrayFormulas = new PositionSet({}); | ||
private spreadingRelations = new SpreadingRelation(); | ||
private positionsToInvalidate: RTreeBoundingBox[] = []; | ||
|
||
constructor(private readonly context: ModelConfig["custom"], getters: Getters) { | ||
this.getters = getters; | ||
|
@@ -304,6 +305,8 @@ export class Evaluator { | |
this.evaluatedCells.set(position, evaluatedCell); | ||
} | ||
} | ||
|
||
this.invalidatePendingPositionsStack(); | ||
onIterationEndEvaluationRegistry.getAll().forEach((callback) => callback(this.getters)); | ||
} | ||
if (currentIteration >= MAX_ITERATION) { | ||
|
@@ -395,7 +398,7 @@ export class Evaluator { | |
// thanks to the isMatrix check above, we know that formulaReturn is MatrixFunctionReturn | ||
this.spreadValues(formulaPosition, formulaReturn) | ||
); | ||
this.invalidatePositionsDependingOnSpread(formulaPosition.sheetId, resultZone); | ||
this.positionsToInvalidate.push({ zone: resultZone, sheetId: formulaPosition.sheetId }); | ||
return createEvaluatedCell( | ||
nullValueToZeroValue(formulaReturn[0][0]), | ||
this.getters.getLocale(), | ||
|
@@ -412,6 +415,32 @@ export class Evaluator { | |
this.nextPositionsToUpdate.addMany(invalidatedPositions); | ||
} | ||
|
||
private invalidatePendingPositionsStack() { | ||
if (this.positionsToInvalidate.length > 0) { | ||
// the result matrices are split in subzones to exclude the array formula position. | ||
// This avoids to invalidate the topleft position of an array formula | ||
// and create an infinite loop of self-invalidation | ||
const boundingboxes = this.positionsToInvalidate | ||
.map((range) => | ||
excludeTopLeft(range.zone).map((zone) => ({ | ||
sheetId: range.sheetId, | ||
zone, | ||
})) | ||
) | ||
.flat(); | ||
const invalidatedPositions = this.formulaDependencies().getCellsDependingOn(boundingboxes); | ||
for (const range of this.positionsToInvalidate) { | ||
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. So this removes the top-left cells from the positions to invalidate ... wasn't this already done in the 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. So are they ranges or positions ? I feel like we could improve the naming here |
||
invalidatedPositions.delete({ | ||
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. this is causing the issue @hokolomopo posted on the task chatter. |
||
sheetId: range.sheetId, | ||
col: range.zone.left, | ||
row: range.zone.top, | ||
}); | ||
} | ||
this.nextPositionsToUpdate.addMany(invalidatedPositions); | ||
this.positionsToInvalidate = []; | ||
} | ||
} | ||
|
||
private assertSheetHasEnoughSpaceToSpreadFormulaResult( | ||
{ sheetId, col, row }: CellPosition, | ||
matrixResult: Matrix<FunctionResultObject> | ||
|
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.