-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ram usage increases until system freeze/crash #2
Comments
same problem |
I opened a issue because im not sûre if its linked to how zed work or thé extensions |
Thanks for raising this issue @sanmue and others, I'm a little swamped this week, so will look at this during the weekend and come back to you. |
Is anyone facing this issue on macOS as well? |
yes, me. |
Update: I have narrowed down the issue - it's occurring due to the tree-sitter configuration in the extension. My current best guess is this: since we are re-using the yaml grammar for ansible files, it's somehow accidentally creating a memory leak because we are using the same parser name for two different languages. As the tree-sitter configuration for this extension is using a different repo than what's being used by Zed for yaml, I tried switching to the same exact configuration for this extension in my local, but that unfortunately doesn't help either. As such, I think we might need help from upstream for this. |
@kartikvashistha There should not be an interaction between the two similar tree-sitter grammars. One small difference, we are using zed-industries/tree-sitter-yaml and the extension appears to be using tree-sitter-grammars/tree-sitter-yaml, both are forks of ikatyang/tree-sitter-yaml. Here's the diff -- we're a single commit ahead. Can you share any additional details about what led you to believe this is caused by the tree-sitter grammar ruling out ansible-language-server, ansible-lint, etc? Am I correct in stating that this has only been observed on Linux? I wanted to point you in the direction of Do you have any steps for reproduction (ideally on an open source repo) beyond "hack on some ansible scripts until it crashes"? |
Hey @notpeter, thanks for reaching out here! Apologies for the delay on my end. As you rightfully observed, the Zed project and this extension are using two different versions of
Sure - I first started looking into the lsp and ansible-lint to ensure they weren't causing an issue. After finding no luck in that area, I moved onto tree sitter highlighting - when I disabled the highlighting provided by this extension locally, the issue vanished!
It was first reported on Linux and I have been able to reproduce it on Linux. However, per a previous comment on this issue, it is observed in macOS as well.
Note, this memory issue occurs only on filetypes detected as YAML, and not Ansible. We just need the Ansible extension installed (and perhaps initialised at least once on an ansible file/project) and then when we start working on YAML files (that are not detected as Ansible files), the memory issue kicks in when editing the YAML files. Basically, edit the file, make errors in the yaml file, save it and the memory issue kicks in.
For testing, I used this as shared by @yodatak in the original issue reported under the Zed repo. You can start editing any YAML file here and the memory issue will kick in. Per this issue, it looks like your suggestion to disable the yaml-language-server didn't improve things, so perhaps it lends more credence to the theory of something being dodgy on the yaml tree-sitter side of things? Please lmk if I can help in any other way here. Thanks a bunch! |
I'm wondering - if the issue is indeed with tree-sitter, should I push an update that temporarily disables highlighting? At least folks will be able to use the LSP without it crashing the editor... |
I could use a release like that. |
I have the same problem on Linux. I don't even have to edit a file, just opening a big ansible repo and the editor freezes up competely when the ansible plugin is enabled. If it's not enabled, no problem. I get the same freezing even I have no config for it in my settings. Just having it installed is enough to trigger the bug in a ansible repo. Nothing special in the log as far as I can see. Sometimes it even kills my entire Wayland session and the entire desktop is freezing until I reboot the entire machine, while the fan runs loud, so something is working hard doing something.... After reading this thread, I guess it could have to do with syntax highlighting but I couldn't tell. Anything you can do to try and fix this would be very appriciated since I would love to use zed for ansible. |
Just to show you what happens on my system, and I have tons of memory: Before launching zed, over 40 GB memory free Launching zed in a big ansible repo with the extension enabled - it takes less than 5 seconds for all 48 GB of memory to be maxed out and then zed crashes. Maybe it helps to figure out whats wrong - it certainly seems like memory is not being released, but even so, why would the plugin use such an enormous amount of memory so very quickly? So its very interesting. This is without any settings in zed, just the plugin installed. |
@linux-cultist What processes are using the memory? Is it Zed proper or is it a subprocess?
If it's the ansible-language-server or the yaml-language-server misbheaving it's relatively easy to check, e.g. disable the
Note, these files being edited aren't really yaml, they are probably jinja2+yaml. If this is actually the tree-sitter grammar I would love to find a reproduction test case. One bad grammar I think should only be limited to 4GB of ram (32 bit wasm) and Zed should be able to survive the wasm extension host crashing hanging. |
With So its some kind of multiplication effect there between the plugins when its enabled, but its not causing the bug it seems. |
Attaching zed.log so you can see details from one session before it crashes, maybe you see something strange in there. |
I have created a test branch here that disables highlighting: https://github.com/kartikvashistha/zed-ansible/tree/hotfix/disable-highlighting To test this, clone the repo, check out the above branch, and then install it via After disabling highlighting, I haven't seen any crashes when yaml files are opened. Please let us know here, if this is not the case on your machine. Thanks! |
Yes, I can confirm that the hotfix without highlighting works very good, no increased memory usage and stable. It really is night and day. So something happens with the highlighting that eats all memory in seconds. :) |
I performed a few more tests locally:
Regarding number 2, can someone check and confirm the same please? You can do so by pulling the latest changes in the repo, checking out the following commit (which resides in this branch) and installing the extension locally: I think the issue is specifically confined within Per my above findings and observations, I think that it could be more appropriate to track this issue in upstream rather than here as we have been able to sufficiently confirm that the Ansible LSP isn't the issue here - what do you think @notpeter ? Thanks! |
Original upstream ikatyang/tree-sitter-yaml hasn't seen an update in 3yrs so I guess the zed fork zed-industries/tree-sitter-yaml is the logical place to be. Does anyone have an open source repo which triggers this issue? I think that's the part I've been struggling with the most is that everyone seems have a private repo that is unusable and balloons Zed's memory to death -- I believe y'all, but I still haven't seen it for myself and am excited to try and track down the memory leak. I wonder whether all this is just caused because tree-sitter-yaml has no business trying to parse yaml full of jinja2 escape sequences -- it's quite far from valid yaml. It's like trying to use an HTML parser to parse PHP code, you're probably going to have a bad time. There appear to be multiple incomplete Jinja2 tree-sitters:
My cursory glance suggests that none of these is built for Ansible/SaltStack style YAML+Jinja2, but they might be a good prior art (please mind the GPL). Conceivably one could modify tree-sitter-yaml to recognize:
And then escape into the a distinct tree-sitter for the Jinja2 Python DSL. Assuming others validate the stability of your Ansible extension without tree-sitter-yaml, let's get a new version of that extension posted ASAP to keep more folks from getting caught up in this. Thank you all for helping track this down, I appreciate your hard work. |
Currently, it is observed that the YAML TS parser, when resued within the Ansible extension, is creating a memory leak when working with non-ansible YAML files. Since we aren't able to fully narrow down the issue on TS side just yet to rollout the appropriate fix, I'm disabling highlighting temporarily in order for at least the LSP be useful/accessible to the extension users. The issue can be tracked here: kartikvashistha/zed-ansible#2 --------- Co-authored-by: Marshall Bowers <[email protected]>
Hey @notpeter , The only time I have seen the bug kick in is when we are editing YAML files, that aren't detected as an Ansible file. I haven't seen this issue (yet) for YAML files, that are detected as Ansible files. Since Ansible files are typically in the
If you need an Ansible repo to play around with, you can find some example code in this repo. Alternatively, you can use this repo of mine as well. To re-create the error, follow these steps broadly:
Note, for reference, I was using the following repo and commit as referenced by @yodatak in the original upstream issue to test and re-create the bug:
Greatly appreciate your speedy responses here! 🙏🏽 Please lmk anytime if you have any other questions related to this. Thanks! |
Also fyi, it looks the issue tab under Zed's tree-sitter-yaml repo is currently disabled, so I can't file an issue there. |
tested for several days - did not find any problem |
Hi everyone, I have got some good news - I think I have been able to resolve the highlighting and memory leak issues via a workaround. Can someone please help test this please? So far, I have not come across the infamous memory leak when highlighting is enabled via this fix. Install the following commit via
Thanks! |
Yes! Tested the new commit and everything works, no memory leaks, syntax highlighting enabled. So I think this can be pushed as official working version. :) |
This release enables back code highlighting for Ansible files to fix and close [this](kartikvashistha/zed-ansible#2) issue. Other misc changes include: - Bump `zed_extension_api` from `0.0.6` to `0.1.0` - Update project README PR: kartikvashistha/zed-ansible#5
I have shipped the proposed fix now to prod - if nobody reports anything worrying by the weekend, I'll close this issue. Thanks everyone for your support in triaging the issue and testing my fixes along the way - I really, really appreciate it! 😃 |
I noticed some more crashes with the plugin on my laptop today, but its not the same thing. Memory doesnt run out, but it makes zed crash. But the fix above still makes the plugin usable, and now its some other bug that is causing the other crashes. Happens more infrequently too and not always. I will create a new issue for it once I can sit down and find something that reproduces the problem. :) |
Hey @linux-cultist - the only other 'infrequent' crash of the extension that I have encountered in the past is when the completion list returned by LSP is quite large (luckily you should be able to confirm this under Zed's logs when this occurs). I had made a note of this in the README. Do lmk if this is what you see as well, thanks! |
Hey folks, another quick update: After dogfooding the new release for a bit before closing this issue, I think I discovered another increased memory bug: basically, the memory starts to increase anytime a key-value pair is added at the very top of an Ansible file. This partially breaks highlighting and starts to create the increased memory + cpu issue. I have been able to produce it on both macOS and Fedora 41. On macOS, there is a great cpu increase and memory keeps increasing gradually. On Fedora, the memory increases rapidly and OOM basically kills Zed. Restarting the editor fixes both the highlighting (highlighting also gets resolved after closing and reopning the file) and resource usage as well. I have recorded a video showcasing the same: https://youtu.be/7Z--h9EeXeY Honestly, I'm quite stumped on how to proceed next. My best guess is that there is some issue with WASM and Tree-sitter compilation/linking at the extension build stage as I noticed that if I re-use the existing yaml grammar from within the extension like so, then the issue dissapears completely (with a much lower observed resource usage). However, this fails the CI (as pointed here under (2)) which effectively means I cant ship it... Unfortunately, I do not possess sufficient chops yet to further debug it effectively and as such would need help/guidance in helping to fix this. Fyi, both the extension and in built YAML configuration use the exact same grammar configuration, with the only difference being how they are sourced. Maybe I can start with the following first question to @notpeter: is it possible to create an exception somehow to accept such a change? If this change is installed as a dev extension, then I do not see any weird YAML or memory issues. Thanks! |
I have not been able to fix the last memory issue unfortunately - it seems it gets triggered anytime we try to add a yaml sequence or block just before a comment(i use vim motion I have also tried with both the Zed's yaml parser and an identical parser for Ansible (which is a clone of the YAML parser used by Zed for YAML but with a different name so as to avoid memory issues with normal non-ansible YAML files when the extension is installed), but was met with no success (PR). The only way I can get it to work is via such a PR, but i'm unsure if we can submit such a change to Zed's extension repo (or allowed an exception). Hey @notpeter - is it possible for a Zed member familiar with the YAML ts parser, Treesitter and the extension system to have a look here when they get some time (maybe @maxbrunsfeld) and give some pointers, if any? I have unfortunately hit a wall at the moment and would welcome any and all help here. Thanks! |
How are you guys switching off syntax highlighting for the ansible file types? I would like to keep the linter but the memory issue is very annoying, and I'm not seeing a setting for highlighting specifically. |
Hey @artooro - To temporarily get around the memory issue, you can check out any of the following branches and install them manually as a Zed extension:
Since this memory issue isn't completely resolved, I'm thinking of reverting the highlighting changes and keeping it disabled till it gets fixed completely. I'll most likely do that on the weekend and open an issue in the main Zed repo with a report of what all I have discovered so far, as this issue needs to be tracked upstream. |
Thanks for starting this extension.
There seems to be a memory issue at the moment, reported as this zed issue #17412 in combinations with this extension.
After some time ram usage increases until system freeze/crash.
config with recommended settings -> problem stays
Zed2.log
The text was updated successfully, but these errors were encountered: