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

lsp-bridge clogging org-babel-tangle when enabled #942

Open
rezaamashi opened this issue May 14, 2024 · 2 comments
Open

lsp-bridge clogging org-babel-tangle when enabled #942

rezaamashi opened this issue May 14, 2024 · 2 comments

Comments

@rezaamashi
Copy link

I am using literate config for my emacs system. It uses quite a verbose amount of tangled blocks.

but with lsp-bridge enabled, every time I run org-babel-tangle the operation that usually takes short seconds, one time I measured it took up to 3 minutes. I also checked on htop that suddenly there are multiple language server being run.

I believe during the process of tangling a file (I'd argue even also when executing code block) lsp-bridge is not something that is needed to run. as it is simply duplicating the blocks of codes into the target file. As in such activity there is no editing involved, of which lsp-bridge is used for.

This also confirmed by profiler results:
CPU

																	  26770  33% - command-execute
                                                                      26770  33%  - funcall-interactively
                                                                      26644  33%   - org-babel-tangle
                                                                      26644  33%    - apply
                                                                      26644  33%     - +org--dont-trigger-save-hooks-a
                                                                      26644  33%      - let
                                                                      26644  33%       - apply
                                                                      26644  33%        - #<subr org-babel-tangle>
                                                                      25463  31%         - #<compiled 0xbd0f0af1f4c0413>
                                                                      25367  31%          - mapc
                                                                      25353  31%           - #<compiled 0x19ea442aa07d683a>
                                                                      13569  16%            - org-babel-spec-to-string
                                                                       9366  11%             - lsp-bridge-monitor-after-change
                                                                       9366  11%              - if
                                                                       9366  11%               - let
                                                                       9361  11%                - unwind-protect
                                                                       9356  11%                 - progn
                                                                       9356  11%                  - if
                                                                       9351  11%                   - let
                                                                       9277  11%                    - lsp-bridge-complete-other-backends
                                                                       9264  11%                     - let*
                                                                       8676  10%                      - if
                                                                       8573  10%                       - progn
                                                                       8479  10%                        - lsp-bridge-codeium-complete
                                                                       8474  10%                         - let
                                                                       8282  10%                          - if
                                                                       8270  10%                           - lsp-bridge-call-async
                                                                       8112  10%                            - let
                                                                       8112  10%                             - setq
                                                                       8109  10%                              - lsp-bridge-epc-call-deferred
                                                                       8095  10%                               - let
                                                                       8072  10%                                - lsp-bridge-epc-manager-send
                                                                       8063  10%                                 - let*
                                                                       8061  10%                                  - lsp-bridge-epc-net-send
                                                                       8029  10%                                   - let*
                                                                       

Memory

                                                              4,404,721,817  95% - command-execute
                                                              4,404,721,817  95%  - funcall-interactively
                                                              4,398,473,030  95%   - org-babel-tangle
                                                              4,398,473,030  95%    - apply
                                                              4,398,473,030  95%     - +org--dont-trigger-save-hooks-a
                                                              4,398,473,030  95%      - let
                                                              4,398,473,030  95%       - apply
                                                              4,398,465,326  95%        - #<subr org-babel-tangle>
                                                              4,367,814,349  94%         - #<compiled 0xbd0f0af1f4c0413>
                                                              4,367,059,412  94%          - mapc
                                                              4,367,017,052  94%           - #<compiled 0x19ea442aa07d683a>
                                                              3,859,733,590  83%            - lsp-bridge-monitor-after-change
                                                              3,859,733,590  83%             - if
                                                              3,859,733,590  83%              - let
                                                              3,859,729,446  83%               - unwind-protect
                                                              3,859,729,446  83%                - progn
                                                              3,859,729,446  83%                 - if
                                                              3,859,729,446  83%                  - let
                                                              3,859,679,112  83%                   - lsp-bridge-complete-other-backends
                                                              3,859,679,112  83%                    - let*
                                                              3,859,151,740  83%                     - if
                                                              3,859,151,740  83%                      - progn
                                                              3,786,422,555  82%                       - lsp-bridge-codeium-complete
                                                              3,786,131,346  82%                        - let
                                                              3,758,372,962  81%                         - if
                                                              3,758,372,962  81%                          - lsp-bridge-call-async
                                                              3,756,462,690  81%                           - let
                                                              3,756,462,690  81%                            - setq
                                                              3,756,462,690  81%                             - lsp-bridge-epc-call-deferred
                                                              3,756,462,690  81%                              - let
                                                              3,756,458,546  81%                               - lsp-bridge-epc-manager-send
                                                              3,756,458,546  81%                                - let*
                                                              3,756,458,546  81%                                 - lsp-bridge-epc-net-send
                                                              3,754,980,487  81%                                  - let*
                                                              2,049,604,884  44%                                   - encode-coding-string
                                                              1,792,560,588  38%                                    - concat
                                                              1,792,560,588  38%                                     - lsp-bridge-epc-prin1-to-string
                                                              1,792,560,588  38%                                      - let
                                                              1,792,048,912  38%                                       - save-current-buffer
                                                              1,791,253,978  38%                                        - unwind-protect
                                                              1,790,324,287  38%                                         - progn
                                                              1,786,124,893  38%                                            let
                                                                    929,691   0%                                         + and
																						...

PS: This is also the case even when lsp-bridge-enable-org-babel is set to nil

@manateelazycat
Copy link
Owner

I don't use org-mode, you can add some check condtion in function lsp-bridge-monitor-after-change to avoid lsp-bridge start in org-babel-tangle

@rezaamashi
Copy link
Author

rezaamashi commented May 24, 2024

Hello, I haven't checked back on this issue for quite a while now. I had a different approach to resolving this issue. I haven't checked on lsp-bridge-monitor-after-change, but I decided to have a shell script that will run a minimal emacs instance specifically for tangling the code.

I have short script called org-tangle-file

  #!/usr/bin/env bash

  set -e
  emacs --batch -l org --eval "(org-babel-tangle-file \"$1\")"

Then I write a callable in emacs that will run that script within emacs

(defun tangle-config-org ()
  "Callable that runs `org-tangle-file' script"
  (interactive)
  (shell-command (concat "org-tangle-file "
                         (expand-file-name "config.org" doom-user-dir))))

Finally, I have a local variable set up at EOF of my config.org that will add tangle-config-org into after-save-hook.

* Local Variable

# Local Variables:
# eval: (add-to-list 'after-save-hook 'tangle-config-org)
# End:

That way every time I save my config.org there will be a lean and minimal instance of emacs running just to tangle the file. I believe this is a more better approach, as it is more modular and the amount of package that I have installed on my setup won't affect the tangling process. For I find, through my experience, if it was not lsp-bridge there are some other package that will intrude into the tangling operation.

Although, still at the same spirit, having packages needlessly intruding into operation where it is not supposed to be would be ideal.
Cheers,

PS. As in my case it is somewhat solved, even with different approach from the proposed one. I am willing to have this issue closed by @manateelazycat. But if someone else have a different and more suitable, package level, approach. I believe it is also swell to have the discussion going.

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