Skip to content

Fix GC memory leak (2) - #4513

Merged
zurfyx merged 3 commits into
mainfrom
mem-leak-2
May 19, 2023
Merged

zurfyx merged 3 commits into
mainfrom
mem-leak-2

Conversation

@zurfyx

@zurfyx zurfyx commented May 17, 2023

Copy link
Copy Markdown
Member

The hardcoded condition on the test (const node = $getNodeByKey('1');) was hiding that the fix in #4510 was actually not good enough.

Subtrees fail. For example, if a subtree is deleted and we visit the parent later, their children might not have deleted (previously deleted)

This PR stores the dirtyElements keys to delete and does the deletion later, without interfering with the loop itself.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 17, 2023
@vercel

vercel Bot commented May 17, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2023 3:11pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2023 3:11pm

@github-actions

github-actions Bot commented May 17, 2023 •

Copy link
Copy Markdown

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/lexical/dist/Lexical.js 27.25 KB (0%) 546 ms (0%) 78 ms (+43.61% 🔺) 623 ms
packages/lexical-rich-text/dist/LexicalRichText.js 38.2 KB (0%) 765 ms (0%) 89 ms (-14.72% 🔽) 853 ms
packages/lexical-plain-text/dist/LexicalPlainText.js 38.18 KB (0%) 764 ms (0%) 104 ms (+22.19% 🔺) 867 ms

Comment thread packages/lexical/src/LexicalGC.ts Outdated
Comment on lines +112 to +115
const nodeMapDeleteLength = nodeMapDelete.length;
for (let i = 0; i < nodeMapDeleteLength; i++) {
nodeMap.delete(nodeMapDelete[i]);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, for .. of is cooler 😎

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fantactuka - Is it also faster for arrays? afaik we started using for..of as a replacement for Array.from(<iterable = Set|Map)

@zurfyx
zurfyx merged commit 434af9e into main May 19, 2023
vuamitom pushed a commit to bitbriks/lexical that referenced this pull request May 19, 2023
This was referenced May 23, 2023
@fantactuka
fantactuka deleted the mem-leak-2 branch July 6, 2023 20:15

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 13bc99ec Deployed May 19, 2023 by vercel[bot]
Preview – lexical — 13bc99ec Deployed May 19, 2023 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants