Live data from Hacker News

Finding and fixing Ghostty's largest memory leak

mitchellh.com

91–100 of 152 posts

Re: Finding and fixing Ghostty's largest memory leak

#91

I've been following the development of Ghostty for a while and while I have the feeling that there is a bit of over-engineering in this project, I find this kind of bug post mortem to be extremely valuable for anyone in love with the craft.

Over-engineered in what way?

Having to introduce a new language stack to distributioms just to be able to build a terminal emulator is what I would consider over-engineering.

Re: Finding and fixing Ghostty's largest memory leak

#92

Earlier quoted context omitted.

Was going to say this, but I don't think anyone actually wants to hear that Rust actually would have helped here. As you're saying, the bug was the equivalent of an incorrectly written Drop implementation. Nothing against Zig, and people not using Rust is just fine, but this is what happens when you want C-like feel for your language. You miss out on useful abstractions along with the superfluous ones. "We don't need…

If you wanted to match Ghostty's performance in Rust, you'd need to use unsafe in order to use these memory mapping APIs, then you'd be in the exact same boat. Actually you'd be in a worse boat because Zig is safer than unsafe Rust.

Please don’t get defensive and spread silly FUD. You can be proud of what you’ve accomplished without feeling sad that a different language has strengths that yours doesn’t.

Calling unsafe mmap APIs not only is unlikely to run into the corner cases where unsafe Rust is tricky to get right, there’s “millions” of crates that offer safe APIs to do so and it’s fundamentally not hard to write it safely (it would be very hard to write it to have any issues).

And fundamentally I think Rust is much more likely to be easier to get high performance because the vast majority of safe code you write is amenable to the compiler performing safe optimizations that Zig just can’t do regarding pointer aliasing (or if it does brings all the risks of of unsafe Rust when the user annotates something incorrectly).

Re: Finding and fixing Ghostty's largest memory leak

#93
post #88

I hate to say it, but this probably would not have happened in a garbage collected language. GC languages are fast these days. If you don't want a runtime like C# (which has excellent performance) a language like Go would have worked just fine here, compiling to a small native binary but with a GC. I don't really understand the aversion to GC's. In memory constrained scenarios or where performance is an absolute top…

I agree that garbage collection is fine and Go indeed has an amazing garbage collector. Unfortunately, it also has the worst type system of all mainstream languages created in the 21st century, so the benefits are rarely worth the drawbacks.

Go's type system is fine. This kind of comment is just pointless and goes against HN rules.

Re: Finding and fixing Ghostty's largest memory leak

#94
post #49

Earlier quoted context omitted.

I honestly don't understand why a terminal emulator needs to be performant. Seems like peak bikeshedding to me.

A lot of developers use the terminal as their primary interaction with the computer. Nvim, tmux, etc. Having it be fast is an extreme quality of life improvement. For devs who only ever use the terminal integrated into their ide then it’s probably less important.

Can you elaborate on that a bit, please?

I have never found myself in the situation where my terminal emulator would be too slow and I‘m using it for the majority of my day-to-day work.

I honestly never ran into a situation where I would habe blamed the terminal emulator for being too slow.

Re: Finding and fixing Ghostty's largest memory leak

#95
post #49

Earlier quoted context omitted.

I am not sure on what your commented is based on, but in short: No? High performance software needs to deal with memory, and optimisations often will need some kind of direct control - as in this example where re-using memory is more performant than constantly churning with mmap.

I honestly don't understand why a terminal emulator needs to be performant. Seems like peak bikeshedding to me.

Well, perhaps “performant” isn’t the word you should be using. All code should be performant, where performant is defined as performing at an acceptable level. You might be tempted to then ask if it needs to be ultra high performance? That’s a better question but still off the mark. The correct question is whether YOU need an ultra high performance terminal emulator? If you don’t, you’re free to not use it. I haven’t found a need for it myself, for instance, and I still use the vanilla MacOS term. But that doesn’t mean someone else hasn’t wanted a faster term than the MacOS term and I wouldn’t throw shade on them for scratching that itch, even if I don’t share it.

Re: Finding and fixing Ghostty's largest memory leak

#96

Earlier quoted context omitted.

If you wanted to match Ghostty's performance in Rust, you'd need to use unsafe in order to use these memory mapping APIs, then you'd be in the exact same boat. Actually you'd be in a worse boat because Zig is safer than unsafe Rust.

Please don’t get defensive and spread silly FUD. You can be proud of what you’ve accomplished without feeling sad that a different language has strengths that yours doesn’t. Calling unsafe mmap APIs not only is unlikely to run into the corner cases where unsafe Rust is tricky to get right, there’s “millions” of crates that offer safe APIs to do so and it’s fundamentally not hard to write it safely (it would be very h…

I don't think this is silly FUD. The article describes a scenario where the low-level abstractions itself was buggy in a subtle way, the comparison to "unsafe" Rust seems entirely fair to me. (edited for typos)

Re: Finding and fixing Ghostty's largest memory leak

#97
post #91

Earlier quoted context omitted.

Over-engineered in what way?

Having to introduce a new language stack to distributioms just to be able to build a terminal emulator is what I would consider over-engineering.

So anything that uses a less popular language is considered over engineering? Distros support lots of different languages already and there are likely other packages built with zig already.

Re: Finding and fixing Ghostty's largest memory leak

#98

I hate to say it, but this probably would not have happened in a garbage collected language. GC languages are fast these days. If you don't want a runtime like C# (which has excellent performance) a language like Go would have worked just fine here, compiling to a small native binary but with a GC. I don't really understand the aversion to GC's. In memory constrained scenarios or where performance is an absolute top…

Why do you think trippling the memory usage of a program is an acceptable tradeoff? It's not just GC pauses that are problematic with gc languages. Some software wants to run on systems with less than 4GiB of RAM.

Re: Finding and fixing Ghostty's largest memory leak

#99

I hate to say it, but this probably would not have happened in a garbage collected language. GC languages are fast these days. If you don't want a runtime like C# (which has excellent performance) a language like Go would have worked just fine here, compiling to a small native binary but with a GC. I don't really understand the aversion to GC's. In memory constrained scenarios or where performance is an absolute top…

Why do you think trippling the memory usage of a program is an acceptable tradeoff? It's not just GC pauses that are problematic with gc languages. Some software wants to run on systems with less than 4GiB of RAM.

[flagged]

Re: Finding and fixing Ghostty's largest memory leak

#100
post #49

Earlier quoted context omitted.

I am not sure on what your commented is based on, but in short: No? High performance software needs to deal with memory, and optimisations often will need some kind of direct control - as in this example where re-using memory is more performant than constantly churning with mmap.

I honestly don't understand why a terminal emulator needs to be performant. Seems like peak bikeshedding to me.

I also didnt get it until I tried ghostty and saw the results of the command appear before even taking my finger off the enter key
Post reply on HN