Optimizing Code With ChatGPT

As a solo developer, I often find myself seeking ways to optimize my code without the luxury of pair programming. That’s where ChatGPT comes in handy. In this blog post, I’ll share my experience of using ChatGPT to improve the performance of my related posts generator.

Getting Started with ChatGPT

To begin, I feed all the code that needs optimization into ChatGPT and ask if there’s any way for it to be improved. It generally provides me with a list of suggestions, some of which may be duplicates (the same change described in different ways). I’ve tried asking ChatGPT to apply the changes for me but more often than not this breaks things. It applies all the changes and they all conflict and everything goes wrong. So while it’s tempting to rely on ChatGPT entirely, I’ve learned that manually checking then implementing each suggestion is quicker and safer.

Profiling for Performance

In order to identify the areas needing improvement, I perform profiling on my codebase. This allows me to pinpoint the slowest parts of the program. Although ChatGPT can guess what might be causing performance issues, it isn’t aware of the actual bottlenecks within the code. Often optimisations it offers make little improvement to the overall performance, so it’s important to work out where the bottleneck is and focus on that.

Tackling Slow Functions

The specific task at hand was optimizing related posts generation for my websites. On smaller sites, this process was fast, but larger sites experienced significant delays. For example, Binary Moon (over 400 posts) used to take around 20 seconds to build.

After profiling, I discovered that the function responsible for calculating Jacard Similarity 1 between two arrays was causing major slowdowns. My original implementation was concise but inefficient. However, by rewriting the function as a longer function with less array manipulation involved, I was able to reduce processing time from 20 seconds to just 5 seconds - a substantial improvement.

While waiting times during deployment were not critical at the moment, this slowness impacts my approach of iterating quickly and will only get worse as the size of my websites increase.

Collaborating with ChatGPT

It’s important to note that while ChatGPT lacks true understanding of coding concepts and best practices, collaborating with it effectively has helped me make more optimal decisions in terms of code efficiency and performance.

By working through ChatGPT’s suggestions, carefully selecting the ones I deemed valuable, and implementing them manually, I have been able to fine-tune my codebase for better performance.

Even as a solo developer, optimizing code doesn’t have to be a daunting task. Thanks to the assistance of ChatGPT and careful collaboration, I’ve been able to improve the efficiency of my related posts generator. While it may not be a perfect solution, it certainly provides valuable insights that can lead to more optimal code.


  1. Jacard Similarity measures the similarity between two sets (arrays) by looking at the ratio of shared elements to the total unique elements in both sets. It’s a way to figure out how much two sets have in common. 

Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).

Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

20 Jul 2016

Empathy in Web Design

I wasn’t able to make WordCamp Europe this year, but they’ve been really quick at getting all of the talks online, and so I have been watching some of them – and this one stood out.Morten Rand-Hendriksen is an experienced...
15 Jun 2023

How I Use AI to Streamline My Programming Process

As a programmer, I am always on the lookout for ways to improve my workflow. In recent years, artificial intelligence (AI) has become an increasingly popular tool in the tech world, and I have found myself using it more and...
20 Feb 2013

The Amazing Art of Flipping Websites

Recently I have looked at expanding my internet empire. I have all sorts of ideas and never enough time – so I thought I would see if I could buy some websites relatively cheaply, improve them, and then either flip...
17 Sep 2010

Unexpected Benefits of A/B Testing

I am currently beta testing a new website called Optimizely – a super simple A/B testing product… and it’s gotten me thinking.A/B testing is a process that allows you to optimize your website for your users. You create one or...
28 Aug 2009

Binary Moon WordPress design vIII

As I briefly mentioned on Monday, I have finally redesigned Binary Moon.I actually started redesigning about 2 years ago. Initially it was going to be an update rather than a totally new look, and I even built most of it,...