logoalt Hacker News

ChrisMarshallNYtoday at 12:47 PM2 repliesview on HN

I just had to rewrite a screen written by an LLM.

It started, by giving me a 2,500-line (about 50% documentation) viewcontroller that ate so much memory that the app would jetsam after the user just did a couple of things.

I then, spent about a week, tracking down memory issues, until we narrowed it down to the MapKit cache. All this time, the LLM was making the code scarier and scarier. It was exactly what I would expect from an inexperienced (but smart) engineer, panicking, and adding more and more cruft.

The LLM ended up suggesting fixes that didn’t work that well, and made the UI janky. Also, it was terrifyingly delicate. I don't think it would have survived one feature request.

By now, the viewcontroller was over 4,000 lines.

I asked the LLM to refactor for redundancy, quality, and size.

It removed all the documentation and logging, reducing the size back to about 2,500 lines (about 1% documentation).

Yay.

Except all of the bush-league threading and awful workaround shit was still in there, but now impossible to understand.

At this point, I gave up, threw out the LLM code, and rewrote the viewcontroller from scratch. Took a day and a half. I figured out how to force MapKit to flush its cache (2 lines of code). It's a well-known issue, and the solution was the first StackOverflow answer that showed up in the search.

It’s currently about 1,400 lines (about 50% is documentation), and works great.

Lesson learned.


Replies

fransje26today at 2:09 PM

> It removed all the documentation and logging, reducing the size to about 2,500 lines. [..] but now impossible to understand.

Nice. Lol.

> At this point, I gave up, threw out the LLM code, and rewrote the code. It’s currently about 1,400 lines (about 50% is documentation), and works great.

I've had similar experiences. But I must be "holding it wrong", judging by all the other articles on HN..

dparktoday at 3:29 PM

I get the impression that your takeaway is not to use LLMs, but I think your takeaway should be to give them more oversight. The way you describe this, it sounds like you went pure vibe coding.

> I asked the LLM to refactor for redundancy, quality, and size.

What did you expect when you asked it to make it smaller?

I’ve had good success with LLM refactoring. But the refactoring has never been “go make this better and smaller”. It’s “go do this specific thing to reduce redundancy” or maybe “give me a list of ways to improve the code redundancy” and then iterate with the LLM to improve the ideas and execute on the right ones.

I don’t think you can just vibe code your way out of a vibe coded mess.

show 1 reply