xenodium / chatgpt-shell

ChatGPT and DALL-E Emacs shells + Org babel 🦄 + a shell maker for other providers
https://xenodium.com
GNU General Public License v3.0
804 stars 73 forks source link

Memory leak? #129

Open guibor opened 1 year ago

guibor commented 1 year ago

Whenever I use chatgpt-shell I notice the performance of my Emacs slowly degrading and it's memory footprint increasing to amazing sizes.

#### System Info :computer:
- OS: darwin
- Emacs: 29.0.91
- Spacemacs: 0.999.0
- Spacemacs branch: develop (rev. 5ab4bde3e)
- Graphic display: t
- Running in daemon: nil
- Distribution: spacemacs
- Editing style: hybrid
- Completion: (compleseus csv dap emacs-lisp emoji ess fasd finance git graphviz html imenu-list javascript json latex lsp lua markdown multiple-cursors neotree octave osx outshine org pdf protobuf python ruby rust search-engine shell slack solidity spotify sql swift toc djvu tree-sitter typescript xkcd yaml treemacs)
- Layers:
```elisp
(dart
 (java :variables java-backend 'lsp)
 mu4e better-defaults clojure compleseus csv dap dart emacs-lisp emoji ess fasd finance git graphviz html imenu-list javascript json latex lsp lua markdown multiple-cursors neotree octave osx outshine pdf protobuf python ruby rust search-engine shell slack solidity spotify sql swift toc
 (tree-sitter :variables spacemacs-tree-sitter-hl-black-list
              '(js2-mode rjsx-mode)
              tree-sitter-syntax-highlight-enable t tree-sitter-fold-enable t tree-sitter-fold-indicators-enable t)
 typescript xkcd yaml treemacs)
xenodium commented 1 year ago

Thanks for reporting. I think we would need more details. Would you be keen troubleshoot and see if you can perform specific actions and measure memory usage before and after? Can't say I have any Emacs experience in this space. I could use the help.

guibor commented 1 year ago

What specific actions or extra details do you suggest? Happy to help.

xenodium commented 1 year ago

Can't say I'm familiar with debugging Emacs memory issues. Anything you can do to try to isolate user actions that lead to memory consumption (and measure) would be helpful. If you figure out a way to measure (maybe after explicitly invoking garbage collector), could also be used to check if memory is restored when shell buffers are killed.

xenodium commented 1 year ago

Source highlighting is pretty innefficient at the moment. Added chatgpt-shell-highlight-blocks so it can be turned off. Try that and see if you notice better performance.

Also, it'd be good to know if the sluggishness goes away if the shell buffers are killed.

guibor commented 1 year ago

I will try it out. I'm optimistic, because the times at which I feel the greatest lag are indeed when the shell refreshes to highlight a new code block (at times Emacs goes blank until the buffer refreshes).

Buffers killed doesn't seem to help though.

guibor commented 11 months ago

I can confirm that it is the block highlighting that is affecting performance. Might be worth optimizing.

xenodium commented 11 months ago

Not had a chance to look into this. In the mean time, maybe this helps (after clearning or killing shell buffers)? https://indieweb.social/@lispi314@mastodon.top/111184372065140896

(when (symbol-function 'malloc-trim)
  (add-hook 'post-gc-hook #'malloc-trim))
guibor commented 11 months ago

Thanks for the suggestion. 'malloc-trim is not defined though in my version of emacs (Mac osx)

gopar commented 3 weeks ago

Looks like I've run into some issues as well. I've been having some sluggish/slow behavior in emacs for a while but couldn't pin it down until now. Looks like chatgpt-shell syntax highlighting is the source.

Only when there is visible colorized text (eg code block), that's when the slowness kicks in.

Turning off syntax highlighting for now