Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactored lsp--create-filter-function for lower latency and higher efficiency#4796

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
eval-exec wants to merge1 commit intoemacs-lsp:master
base:master
Choose a base branch
Loading
fromeval-exec:exec/lsp--create-filter-function

Conversation

@eval-exec
Copy link
Contributor

@eval-execeval-exec commentedMay 26, 2025
edited
Loading

  • I added a new entry toCHANGELOG.md

  • I updated documentation if applicable (docs folder)

This PR rewriteslsp--create-filter-function to use a buffer-based approach for processing incoming LSP messages. The new implementation accumulates raw input in a dedicated buffer, parses headers to determine message boundaries, and only decodes and processes complete messages. This design:

  • Reduces latency: Callslsp--parser-on-message immediately for each complete message instead of batching, improving responsiveness.
  • Improves efficiency: Avoids unnecessary string concatenations and memory copies by operating directly on buffers.
  • Enhances robustness: Properly handles incomplete header/body splits across multiple input chunks.

The new logic closely follows the LSP protocol framing, ensuring correctness and better performance, especially with large or fragmented messages.

No changes to external API or user-facing behavior.
All message parsing and dispatching are now handled more efficiently and reliably.

kiennq reacted with thumbs up emoji
@eval-execeval-exec changed the titleRefactor lsp--create-filter-function for better performanceRefactored lsp--create-filter-function for lower latency and higher efficiencyMay 26, 2025
@eval-execeval-exec marked this pull request as draftMay 26, 2025 03:42
@eval-execeval-exec marked this pull request as ready for reviewMay 26, 2025 03:55
@eval-execeval-exec marked this pull request as draftMay 26, 2025 03:56
@eval-execeval-execforce-pushed theexec/lsp--create-filter-function branch from4387762 to009f023CompareMay 26, 2025 08:59
@eval-execeval-exec marked this pull request as ready for reviewMay 26, 2025 09:01
@kiennq
Copy link
Member

The CI is failing which indicates that there might be edge case where this change fails to work. Can you make the CI passes?

eval-exec reacted with heart emoji

@eval-exec
Copy link
ContributorAuthor

eval-exec commentedMay 27, 2025
edited
Loading

The CI is failing which indicates that there might be edge case where this change fails to work. Can you make the CI passes?

Thanks for pointing it out. I’ll take a look and fix it later.

@eval-execeval-execforce-pushed theexec/lsp--create-filter-function branch 5 times, most recently from2807ef2 to5876bbfCompareMay 29, 2025 13:49
@eval-exec
Copy link
ContributorAuthor

@kiennq Hello, CI passed, request code review. Thank you.

lsp-mode.el Outdated
;; Copy and decode body
(with-current-buffer json-body-buffer
(erase-buffer)
(insert-buffer-substring input-buffer body-start body-end)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? Can't we do that in theinput-buffer, i.e., move the cursor to header end and just calllsp-json-read-buffer, we save one copy to body buffer

lsp-mode.el Outdated
while (let* ((header-end (search-forward "\r\n\r\n" nil t))
(content-length-start (search-backward "Content-Length:" nil t)))
(when header-end
(let* ((headers (buffer-substring content-length-start (- header-end 4)))
Copy link
Member

Choose a reason for hiding this comment

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

Usebuffer-substring-no-properties

(lsp--on-notification workspace json-data))
('request (lsp--on-request workspace json-data)))))))

(defun lsp--create-filter-function (workspace)
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a benchmark to see if this is really faster than the old one?
The old one already using temp buffer at the final step as part of optimization, this change expands that more so that we don't keep the list of input chunks but concat them right away.

Another thing withlsp--parser-on-message is that we can dispatch it on a timer, so we don't have to wait for a handler to run to parse the next one. The previous approach is we parsing all available message first and dispatch them one by one. The new approach on the other hand will try to executelsp--parser-on-message as soon as we have data, however that can led to a long waiting period, especially around something like waiting for completion result.

@eval-execeval-execforce-pushed theexec/lsp--create-filter-function branch 2 times, most recently frome580c8b todc49d69CompareMay 30, 2025 17:33
Signed-off-by: Eval EXEC <execvy@gmail.com>
@eval-execeval-execforce-pushed theexec/lsp--create-filter-function branch fromdc49d69 toa2d1a6eCompareMay 30, 2025 17:34
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kiennqkiennqkiennq left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@eval-exec@kiennq

[8]ページ先頭

©2009-2025 Movatter.jp