Skip to content

perf: this caches the transaction diffing to not have to recompute #1656

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/core/src/api/nodeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ function areBlocksDifferentExcludingChildren<
);
}

const blocksChangedMap = new WeakMap<
Transaction,
{
appendedTransactions: Transaction[];
blocksChanged: BlocksChanged<any, any, any>;
}
>();
const defaultAppendedTransactions: Transaction[] = [];

/**
* Get the blocks that were changed by a transaction.
* @param transaction The transaction to get the changes from.
Expand All @@ -161,8 +170,15 @@ export function getBlocksChangedByTransaction<
SSchema extends StyleSchema = DefaultStyleSchema
>(
transaction: Transaction,
appendedTransactions: Transaction[] = []
appendedTransactions: Transaction[] = defaultAppendedTransactions
): BlocksChanged<BSchema, ISchema, SSchema> {
if (
blocksChangedMap.has(transaction) &&
blocksChangedMap.get(transaction)!.appendedTransactions ===
appendedTransactions
) {
return blocksChangedMap.get(transaction)!.blocksChanged;
}
let source: BlockChangeSource = { type: "local" };

if (transaction.getMeta("paste")) {
Expand Down
Loading