AI Coding Agents Just Made Shopify's Template Engine 53% Faster

    Tobias Lutke used AI agents to optimize Liquid, Shopify's 20-year-old template engine. The results are eye-opening for anyone wondering what AI coding agents can actually accomplish.

    Tob

    Tob

    Backend Developer

    4 min readAI Engineering
    AI Coding Agents Just Made Shopify's Template Engine 53% Faster

    Shopify CEO Tobias Lütke just did something interesting. He used an AI coding agent to find performance optimizations in Liquid, Shopify's open-source Ruby template engine that's been around since 2005. The result: a 53% speed improvement across parse and render operations.

    This matters because Liquid is a mature codebase that's seen contributions from hundreds of developers over two decades. If AI agents can still find significant wins here, the implications are worth thinking about.

    TL;DR: AI agents found 93 optimization opportunities in Shopify's Liquid template engine using a technique called "autoresearch." One change alone (replacing StringScanner with byte-index searching) delivered a 12% speed boost. The key insight: robust test suites unlock agent-driven optimization.

    How Autoresearch Works

    Andrej Karpathy's autoresearch pattern gives a coding agent a benchmark and asks it to run hundreds of semi-autonomous experiments to find improvements. The agent tries variations, measures results, and accumulates what works.

    Tobi started with a simple prompt file and a shell script. The agent ran the test suite, measured benchmarks, and reported back. Two days later, 93 commits from around 120 experiments landed in a single PR.

    This works because the agent isn't guessing. It has concrete numbers to optimize against. The test suite acts as a safety net. Without 974 unit tests, this kind of rapid experimentation would be too risky.

    What Actually Worked

    Several micro-optimizations added up:

    • StringScanner replacement: Single-byte byteindex searching beat regex-based skip_by about 40%, reducing parse time by 12% alone.
    • Manual byte scanning: Eliminated costly StringScanner#string= resets that happened 878 times per render.
    • Frozen string caching: Pre-computed strings for integers 0-999 saved 267 Integer#to_s allocations per render.

    None of these are revolutionary individually. But the agent found them systematically, measured them precisely, and stacked them together.

    The Bigger Picture

    Simon Willison pointed out something worth considering: CEOs can code again. High-interruption roles used to make hands-on coding impractical. Coding agents change that equation. You can delegate the experiment execution while staying in the loop on decisions.

    The test suite point is equally important. If you want AI agents to improve your code, you need good tests first. That's the unlock that makes everything else possible.

    Sources: Simon Willison, GitHub/Shopify/liquid

    Related Blog

    AI Coding Agents Just Made Shopify's Template Engine 53% Faster | Tob