Skip to content
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

Horrible performance when formating a large file with many changes #1635

Open
daiyousei-qz opened this issue May 14, 2023 · 1 comment
Open

Comments

@daiyousei-qz
Copy link

Say a file of size S has N independent ranges of changes. When formatting it via LSP, N independent requests are issued and for each request, in clang::format::internal::reformat, clang::tooling::applyAllReplacements is called M times where M is the number of formatting passes. In applyAllReplacements, the entire file content is at least copied once. So at least S * N * M bytes will be copied. Depending on the size of the file and the number of independent ranges, this number could easily reach gigabytes and basically editor will hang.

This is technically not a clangd issue, but a defect from clang-format and LSP. Note someone has already proposed a change to LSP to solve the issue. See also microsoft/vscode#158776 and microsoft/language-server-protocol#1536. I suppose clangd should add support for that once it lands.

@tom-anders
Copy link

tom-anders commented May 18, 2023

Looks like clang-format already supports multiple ranges, so seems like implementation in clangd would be rather straightforward, here's a draft implementing the protocol changes proposed in microsoft/language-server-protocol#1536.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants