syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.68k stars 4.89k forks source link

helm-git-grep causes my computer to crash #15497

Closed JuanCaicedo closed 1 year ago

JuanCaicedo commented 2 years ago

Hi everyone! I opened up an issue because I don't really know how to go about debugging this πŸ˜… I'm seeing this pretty reliably, so if there's any more info I can provide, let me know πŸ‘

Description :octocat:

Computer crashes when running helm-git-grep

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart:

Expected behaviour: :heart: :smile:

System Info :computer:

lebensterben commented 2 years ago

what do you mean by crash?

is it unresponsive?

BenedictHW commented 2 years ago

Helm-git-grep seems to be working fine here on Emacs 29.0.50.

Perhaps try,

(setf helm-candidate-number-limit 100)

and see if that makes helm more responsive? And I thought I'd mention SPC g s l -F (or -G) RET (or refresh with g) as Magit's transient interface to use in the meantime.

HTH,

JuanCaicedo commented 2 years ago

@lebensterben by crash I mean it forces my computer to force restart πŸ˜… I really don't know a better way to describe it.

@BenedictHW Thanks! I can to to set helm-candidate-number-limit to see if that helps πŸ‘

I'm not sure what command you're suggesting. SPC g s triggers magit-status, and there's nothing I can see under SPC g s l. If by the transient interface you mean the magit status view, I'm not sure how I can grep through the whole codebase from there, which is my goal. Thank you for helping though!

BenedictHW commented 2 years ago

There's also the emacs debugger & profiler.

The =Profiler= is a tool that helps you identify why your editor is running slowly or consumes a lot of memory. Here are key bindings related to it:

| Key binding | Description | |-------------+-----------------------------| | ~SPC h P k~ | stop the profiler | | ~SPC h P r~ | display the profiler report | | ~SPC h P s~ | start the profiler | | ~SPC h P w~ | write the report to file |

Regarding SPC g s, that was my bad, I misunderstood you. Inside the SPC g s magit buffer "l" and then "-F" will allow you to grep through commit logs.

To grep the whole codebase the usual method is SPC /. Grep/ag/ripgrep will then search the project, where project is defined by projectile.

https://github.com/bbatsov/projectile

Projectile automatically recognizes version control marker files like .git.

You can bring up a list of projects that projectile recognizes with SPC p p. So navigating to your .emacs.d/doc folder and pressing SPC s d to search just the /doc folder is possible (that's where the above keybind table come from :D ). See also SPC s f, which I've yet to see Doom Emacs replicate, and is handy when you're aiming to grep folders or files that are not in a defined project (C-2 C-h moves two directories up in the SPC f f and SPC s f buffer!).

I hope this solves your use case, or at least can give us some debug clues to work with.

Cheers,

Juan Caicedo @.***> writes:

@lebensterben by crash I mean it forces my computer to force restart πŸ˜… I really don't know a better way to describe it.

@BenedictHW Thanks! I can to to set helm-candidate-number-limit to see if that helps πŸ‘

I'm not sure what command you're suggesting. SPC g s triggers magit-status, and there's nothing I can see under SPC g s l. If by the transient interface you mean the magit status view, I'm not sure how I can grep through the whole codebase from there, which is my goal. Thank you for helping though!

JuanCaicedo commented 2 years ago

@BenedictHW Thanks for responding! helm-candidate-number-limit does not seem to help ☹️

I tried running the profiler, but after my computer crashes I can't recover the results πŸ˜•

SPC / doesn't seem to work very well for me. The results are super slow, to the point where it's not really usable. SPC g / with the same query returns very quickly (until my computer crashes πŸ˜…)

I feel like I'm sort of stuck with this issue πŸ’”

lebensterben commented 2 years ago

@JuanCaicedo

Install ripgrep and use SPC /.

JuanCaicedo commented 2 years ago

I was able to find the crash reports for my system and see that they are all from Process Name = node

Here's the part of the report that seems relevant (though I'm not sure if it's a red herring)

6   node                                   0x1063b6787 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) + 71

I don't know why helm-git-grep would be interacting with node though πŸ˜…

I tried updating my version and am now on v16.14.0, but still get this crash.

@lebensterben Thanks for the tip πŸ˜€ I tried installing ripgrep and the results of SPC / are still very slow. I also tried running ripgrep-regexp and projectile-ripgrep, but neither of these seem to work (I get an error saying that the rg command is not found)

lebensterben commented 2 years ago

it's slow because it's not found so it fallbacks to grep.

it's not found because it's not added to PATH.

BenedictHW commented 2 years ago
  1. Concerning ripgrep.

Can you call ripgrep in your terminal ($ rg)? I'm on debian so I'm not too familiar with brew.

  1. Concerning the node out-of-memory error (OOM).

Without much else to go off of, I'm guessing your out of memory error could be due to long lines when you attempt to open a JavaScript file? But first does the error still persist on your system with a vanilla configuration?

I.e. if you back up your .spacemacs, .emacs.d folder and install a fresh vanilla configuration does SPC g / still crash your system?

I wish I knew more about the node, that's all I got for now. Let us know what happens.

acheng-hm commented 2 years ago

I get the same crash unless I type my search term one character at a time, allowing it to finish before each additional character (or if I build my entire search term elsewhere and paste it in all at once for helm-git-grep).

Is there a setting that I can tweak so it waits more milliseconds after the most recent keystroke before starting its next search? The problem feels like it's spawning "too many" searches when I type quickly.

BenedictHW commented 2 years ago

Running helm-dir-smart-do-search (SPC s d) "helm delay" while in /home/$USER/.emacs.d/elpa/29.0/develop/helm-20220621.1947/ dired buffer gives me helm-grep-input-idle-delay. Still, I am not sure of your root problem. I don't use helm-git-grep much at all, instead I use SPC /.

acheng-hm commented 2 years ago

I setq helm-grep-input-idle-delay to 1.0 but it still died. Maybe helm-git-grep is not one of the affected commands.

Can rg SPC / be configured to find "bar foo" if you type "foo bar" like helm-git-grep does?

Meanwhile setting helm-git-grep-candidate-number-limit super low (like 20) lets it finish fast enough that I can learn to wait after each keystroke.

BenedictHW commented 2 years ago

Ahah. Happy to find somebody else who encountered the same issue. I noticed the same behaviour with rg and SPC /. What allows me to find "bar foo" if you type "foo bar" is using ag (I use the packaged silversearcher-ag) instead of rg. I'm a little foggy on the reasons why this is, it's been awhile since I dug into this, but it is either

  1. Rust's regex library (also used by fdfind) does not support look-ahead or look-arounds. Is this still the case?

  2. Helm-ag package is currently stagnating. It works best with ag and perhaps getting rg to work with helm-ag will require some hacking.

  3. I know a helm-rg package exists, but from the quick glance I took some while ago, it does not seem to equal helm-ag in capabilities yet. So some hacking in order again.

If switching to ag is no issue, then you should get the behaviour that you want. Make sure to set,

helm-ag-fuzzy-match to t.

Here's my config if it proves useful.

  ;; See /home/ben/.config/fd/ignore
  (require 'helm-fd)
  (require 'helm-ag)

  (defvar ben/helm-source-fd
    (helm-make-source
        (format "fd (%s)"
                (abbreviate-file-name default-directory)) 'helm-fd-class)
    "For use of FD in `helm-for-files'. <search_pattern>
<target_dir>. Ex. '.emacs.d /home'")

  (defvar ben/helm-source-maria-ag
    (helm-make-source "Project Maria - AG" 'helm-do-ag-class
      :candidates-process
      (lambda ()
        (helm-ag--do-ag-set-command)
        (helm-ag--do-ag-candidate-process +project-maria-dir+)))
    "To search Project Maria files from `helm-for-files'.
`helm-ag--do-ag-set-source' used as exemplar.")

  (defvar ben/helm-source-emacs-commands
    (helm-build-sync-source "Emacs Commands"
      :candidates (lambda ()
                    (let ((cmds))
                      (mapatoms (lambda (elt)
                                  (when (commandp elt)
                                    (push (symbol-name elt) cmds))))
                      cmds))
      :coerce #'intern-soft
      :action #'command-execute)
    "A simple helm source for Emacs commands. Used in
`helm-for-files'.")

  (setf ace-jump-helm-line-default-action 'select
        helm-ff-auto-update-initial-value t
        recentf-max-saved-items 1000
        ;; FIXME `helm-source-buffers-list' causes, ad-Advice-set-window-buffer:
        ;; Wrong type argument: bufferp, nil when selecting buffer. I'm fairly
        ;; sure the problem is in `spacemacs//helm-open-buffers-in-windows'.
        helm-for-files-preferred-list '(helm-source-buffers-list
                                        helm-source-recentf
                                        ben/helm-source-fd
                                        ben/helm-source-maria-ag
                                        ben/helm-source-emacs-commands)
        helm-candidate-number-limit 100
        helm-ff-skip-boring-files t
        helm-ag-fuzzy-match t
        helm-fd-executable "fdfind"
        helm-fd-switches '("--hidden" "--type" "f" "--type" "d" "--color" "never" "--max-results" "10" "--full-path")
        )

  (spacemacs/set-leader-keys
    "SPC" #'helm-for-files
    (kbd "se") #'helm-mu)
BenedictHW commented 2 years ago

I should mention I set SPC SPC to helm-for-files elsewhere as well as ; to helm-occur. With helm-source-emacs-commads SPC SPC covers both M-x as well as whatever is in your helm-for-files-preferred-list. I'm fairly certain this capability is helm-specific, but who knows, some lisper has probably got something similar for ivy or the new completions consult/embark/corfu/what have you.

BenedictHW commented 2 years ago

I wish I knew more about helm-git-grep, but if you have further questions about helm-git-grep, Evan Klitzke @eklitzke would be the person most likely to know something.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!