Martin Hujer

Blog

Articles about PHP, Symfony, development with AI agents and more, since 2007.

There is no reason for any software to be slow anymore

Improving software performance used to be tedious work with profilers. It turns out that coding agents are really good at it.

It should come as no surprise, because optimization tasks are usually well defined (this page is slow, this API endpoint is slow), easily measurable (is it faster than before?) and verifiable (does it still behave as before?). And that’s the kind of task where agents work best.

If you give your coding agent an environment where it can tinker, there is a good chance it will be able to discover the root cause of the slowness and fix it. And even if you cannot give it access to a production-like environment (e.g. to GCP deployments without your review), it can easily work around the lack of permission by preparing some experiments you review and deploy yourself. The agent then measures the results there. If it knows what your production environment looks like (for example from Terraform code), it can often make a good guess about where the bottleneck is by reading app code locally.

How I halved the response time

Recently, Claude and I cut the response time by 50% by optimizing how the navigation menu is loaded and cached. On production, with its bigger menu, the homepage TTFB went from ~1.0s to ~0.5s. Yes, you read that right, loading the navigation took 50% of the response time 🤷. Claude analyzed the page rendering locally, noticed that the menu is loaded inefficiently and prepared an experiment I then reviewed and deployed to staging. “An experiment” is a fancy name, but in reality it was a query parameter to not render the menu. And with that Claude was able to measure response time with and without the menu on various pages to verify that the menu is indeed the culprit. It turned out that Redis is significantly slower when used via the network in GCP than locally, and the menu made ~150 Redis calls.

Afterwards, Claude refactored how the menu is loaded and cached (one Redis call instead of ~150). It also compared the rendered HTML before and after and added tags to the cache record so that it will be invalidated after any content page changes. Just like that I got a big speed improvement for about an hour of my time.

Where a prompt isn’t enough

I’m aware that there are some reasons for slowness that can’t be easily fixed by a prompt, such as a data model that doesn’t scale, architecture shortcomings (these need a rewrite), slow third-party APIs (they need to run the prompt, not you), or business decisions. As for those business decisions, the cost-benefit ratio should be much better now, making it an easy sell to the business.

Still, I believe there is no excuse for any software to be slow, because the speedup is often just a prompt away.

Try it yourself

I suggest you give it a try right now. Pick either a part of your app you know is slow or something valuable for the business: the homepage or a product detail page. And ask your agent to investigate how it can be made faster. You can use the following prompt or write your own:

Optimize the homepage response time (TTFB). The infrastructure runs on GCP (see terraform/ for details). You have the code and the app available locally. You are not allowed to deploy to GCP, but you can prepare experiments which I can review and deploy to staging for you to measure.

In my case Claude had access to the app running locally in Docker, the source code (including Terraform files) and curl to do the measurements. The better the environment and tools the agent can access, the better the results it will give you.

Comments load Disqus, a third-party service that uses cookies. Disqus privacy policy