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

The reload operation takes up a lot of memory until the computer freezes #4228

Closed
xpeng2333 opened this issue Oct 12, 2022 · 4 comments · Fixed by #4457
Closed

The reload operation takes up a lot of memory until the computer freezes #4228

xpeng2333 opened this issue Oct 12, 2022 · 4 comments · Fixed by #4457
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@xpeng2333
Copy link

Summary

Opening a file with a size of 500M, executing the reload operation will take up much more memory than the file size and keep increasing until all the memory is used up

Reproduction Steps

I tried this:

  1. hx 1.txt
  2. reload
    I expected this to happen:
    reload 1.txt
    Instead, this happened:
    hx used up all memory

Helix log

~/.cache/helix/helix.log
please provide a copy of `~/.cache/helix/helix.log` here if possible, you may need to redact some of the lines

Platform

macOS

Terminal Emulator

zsh 5.8.1

Helix Version

helix 22.08.1

@xpeng2333 xpeng2333 added the C-bug Category: This is a bug label Oct 12, 2022
@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Oct 12, 2022
@the-mikedavis
Copy link
Member

the-mikedavis commented Oct 12, 2022

It isn't an infinite amount of memory but it is quite a lot: for a text file with ~503MB, I see around 21GB of memory usage during the reload and 1GB after.

It looks like helix_core::diff::compare_ropes is the culprit for the increased CPU usage at least, and probably the increased memory usage too:

flamegraph

@kirawi
Copy link
Member

kirawi commented Oct 12, 2022

I'm assuming that this is because of the timeout. After 1 second, all diff operations turn into insertions and deletions as a fast path. And since this is per char, it can get pretty big.

Alternatively, these lines may be the culprit:

let (lower, upper) = changes.size_hint();
let size = upper.unwrap_or(lower);
let mut changeset = ChangeSet::with_capacity(2 * size + 1); // rough estimate

@xpeng2333
Copy link
Author

Thanks for your reply. It seems that I misunderstood the reload operation. I thought it was just reopening the file.

@kirawi
Copy link
Member

kirawi commented Oct 12, 2022

The rsync algorithm is an option for more efficient reloading as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants