Skip to content

Commit

Permalink
[FIX] model: don't flatten command result
Browse files Browse the repository at this point in the history
`array.flat()` is slow because it creates a new array (and allocates memory)

With this commit, we only execute `array.flat()` if the command as been refused
by one of the plugins (for possibly several resons)

`checkDispatchAllowed` self-time could take up to 4% of the total time when loading
a spreadsheet with lots of initial revisions.

Now it's 0.0% :)

closes #3190

X-original-commit: 4991b29
Signed-off-by: Rémi Rahir (rar) <[email protected]>
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
LucasLefevre committed Nov 17, 2023
1 parent 6925dc1 commit 95569a7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ export class Model extends EventBus<any> implements CommandDispatcher {
*/
private checkDispatchAllowed(command: Command): DispatchResult {
const results = this.handlers.map((handler) => handler.allowDispatch(command));
return new DispatchResult(results.flat());
if (results.some((r) => r !== CommandResult.Success)) {
return new DispatchResult(results.flat());
}
return DispatchResult.Success;
}

private finalize() {
Expand Down

0 comments on commit 95569a7

Please sign in to comment.