11 comments

  • brentroose8 hours ago
    A month ago, I went on a performance quest trying to optimize a PHP script that took 5 days to run. Together with the help of many talented developers, I eventually got it to run in under 30 seconds. This optimization process with so much fun, and so many people pitched in with their ideas; so I eventually decided I wanted to do something more.<p>That&#x27;s why I built a performance challenge for the PHP community<p>The goal of this challenge is to parse 100 million rows of data with PHP, as efficiently as possible. The challenge will run for about two weeks, and at the end there are some prizes for the best entries (amongst the prize is the very sought-after PhpStorm Elephpant, of which we only have a handful left).<p>I hope people will have fun with it :)
    • Tade05 hours ago
      Pitch this to whoever is in charge of performance at Wordpress.<p>A Wordpress instance will happily take over 20 seconds to fully load if you disable cache.
      • tracker126 minutes ago
        Wordpress is something that I cannot believe hasn&#x27;t been displaced by a service that uses a separate application for editing and delivery.<p>It seems like something like vercel&#x2F;cloudflare could host the content-side published as a worker for mostly-static content from a larger application and that would be more beneficial and run better with less risk, for that matter. Having the app editing and auth served from the same location is just begging for the issues WP and plugins have seen.
        • devmor3 minutes ago
          As someone who built full ecommerce websites on wordpress over 15 years ago, I can tell you exactly why it hasn&#x27;t been replaced - the plugin&#x2F;theme ecosystem.<p>There are tens of thousands of plugins and themes to make a Wordpress website do whatever you want and look however you want, either for free or a <i>very</i> low fee. You have to replace that entire ecosystem <i>for the same price</i> to replace Wordpress.<p>No matter how many times people get hacked, the perceived value of getting something for nothing outweighs the eventual cost.
      • embedding-shape4 hours ago
        Microbenchmarks are very different from optimizing performance in real applications in wide use though, they could do great on this specific benchmark but still have no clue about how to actually make something large like Wordpress to perform OK out of the box.
      • rectang1 hour ago
        Are you talking about a new, empty WordPress instance running the default theme? Because if so, that doesn&#x27;t match my anecdotal experience.<p>If you&#x27;re talking about a WordPress instance with arbitrary plugins running an arbitrary theme, then sure — but that&#x27;s an observation about those plugins and themes, not core.<p>As someone who has to work with WordPress, I have all kinds of issues with it, but &quot;20 seconds to load core with caching disabled&quot; isn&#x27;t one of them.
      • rkozik19892 hours ago
        Much like anything else your performance is going to vary a lot based on architecture of implementation. You really shouldn&#x27;t deploying anything into production without some kind of caching. Whether that&#x27;s done in the application itself or with memcached&#x2F;redis or varnish or OPcache.
        • LoganDark1 hour ago
          &gt; You really shouldn&#x27;t deploying anything into production without some kind of caching.<p>Citation needed? You only need cache if a render is expensive to produce.
      • monkey_monkey4 hours ago
        That&#x27;s often a skill issue.
        • almosthere1 hour ago
          skill issue being they only know php
    • ge9625 minutes ago
      5 days to 30 seconds? What kind of factor&#x2F;order of magnitude is that damn<p>What takes 5 days to run
      • hosteur7 minutes ago
        Poorly made analytics&#x2F;datawarehouse stuff.
    • onion2k2 hours ago
      <i>A month ago, I went on a performance quest trying to optimize a PHP script that took 5 days to run. Together with the help of many talented developers, I eventually got it to run in under 30 seconds.</i><p>When people say leetcode interviews are pointless I might share a link to this post. If that sort of optimization is possible there is a structures and algorithms problem in the background somewhere.
      • nicoburns2 hours ago
        I find that these kind of optimizations are usually more about technical architecture than leetcode. Last time I got speedups this crazy the biggest win was reducing the number of network&#x2F;database calls. There were also optimisations around reducing allocations and pulling expensive work out of hot loops. But leetcode interview questions don&#x27;t tend to cover any of that.<p>They tend to be about the implementation details of specific algorithms and data structures. Whereas the important skill in most real-world scenarios would be to understand the trade-offs between different algorithms and data structures so that you pick an appropriate off-the-shelf implementation to use.
        • LollipopYakuza1 hour ago
          I agree. The &quot;advanced&quot; leetcode is about those last % of optimization. But when network latency is involved in a flow, it is usually the most obvious low hanging fruit.
      • tuetuopay1 hour ago
        Well leetcode asks you to implement the data structure, not how and when to use which data structure. I don’t need to know how to implement a bloom filter on a whiteboard off the top of my head to know when to use it.
    • CyberDildonics1 hour ago
      Using a language that is 100x slower than naive native programs to do a &quot;speed challenge&quot; is like spending your entire day speed walking to run errands when you can just learn how to drive a car.
    • gib4445 hours ago
      &gt; A month ago, I went on a performance quest trying to optimize a PHP script that took 5 days to run. Together with the help of many talented developers, I eventually got it to run in under 30 seconds<p>That&#x27;s a huge improvement! How much was low hanging fruit unrelated to the PHP interpreter itself, out of curiosity? (E.g. parallelism, faster SQL queries etc)
      • brentroose5 hours ago
        Almost all, actually. I wrote about it here: <a href="https:&#x2F;&#x2F;stitcher.io&#x2F;blog&#x2F;11-million-rows-in-seconds" rel="nofollow">https:&#x2F;&#x2F;stitcher.io&#x2F;blog&#x2F;11-million-rows-in-seconds</a><p>A couple of things I did:<p>- Cursor based pagination - Combining insert statements - Using database transactions to prevent fsync calls - Moving calculations from the database to PHP - Avoiding serialization where possible
        • tiffanyh5 hours ago
          Aren’t these optimizations less about PHP, and more about optimizing how your using the database.
          • toast01 hour ago
            PHP is kind of like C. It can be very fast if you do things right, and it gives you more than enough rope to tie yourself in knots.<p>Making your application fast is less about tuning your runtime and more about carefully selecting what you do at runtime.<p>Runtime choice does still matter, an environment where you can reasonably separate sending database queries and receiving the result (async communication) or otherwise lets you pipeline requests will tend to have higher throughput, if used appropriately, batching queries can narrow the gap though. Languages with easy parallelism can make individual requests faster at least while you have available resources. Etc.<p>A lot of popular PHP programs and frameworks start by spending lots of time assembling a beautiful sculpture of objects that will be thrown away at the end of the request. Almost everything is going to be thrown away at the end of the request; making your garbage beautiful doesn&#x27;t usually help performance.
          • hu34 hours ago
            It&#x27;s still valid as as example to the language community of how to apply these optimizations.
          • swasheck4 hours ago
            in all my years doing database tuning&#x2F;admin&#x2F;reliability&#x2F;etc, performance have overwhelmingly been in the bad query&#x2F;bad data pattern categories. the data platform is rarely the issue
            • tosti2 hours ago
              The worst offenders I&#x27;ve seen were looping over a shitty ORM
              • cobbzilla1 hour ago
                hey don’t forget, that shitty ORM also empowers you to write beautiful, fluent code that, under the hood, generates a 12-way join that brings down your entire database.
              • edoceo1 hour ago
                And that is true across languages.
      • Joel_Mckay3 hours ago
        In general, it is bad practice to touch transaction datasets in php script space. Like all foot-guns it leads to Read-modify-write bugs eventually.<p>Depending on the SQL engine, there are many PHP Cursor optimizations that save moving around large chunks of data.<p>Clean cached PHP can be fast for REST transactional data parsing, but it is also often used as a bodge language by amateurs. PHP is not slow by default or meant to run persistently (low memory use is nice), but it still gets a lot of justified criticism.<p>Erlang and Elixir are much better for clients&#x2F;host budgets, but less intuitive than PHP =3
    • user39393825 hours ago
      exec(‘c program that does the parsing’);<p>Where do I get my prize? ;)
      • brentroose5 hours ago
        The FAQ states that solutions like FFI are not allowed because the goal is to solve it with PHP :)
        • kpcyrd4 hours ago
          What about using the filesystem as an optimized dict implementation?
          • olmo233 hours ago
            this is never going to be faster because it requires syscalls
            • kpcyrd2 hours ago
              The time you lose at the syscall boundary you may be able to win back during much shorter GC pauses.
              • cess111 hour ago
                Some suggestions that are already in the PR list disable GC.<p><a href="https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;function.gc-disable.php" rel="nofollow">https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;function.gc-disable.php</a>
  • Xeoncross3 hours ago
    This is why I jumped from PHP to Go, then why I jumped from Go to Rust.<p>Go is the most battery-included language I&#x27;ve ever used. Instant compile times means I can run tests bound to ctrl&#x2F;cmd+s every time I save the file. It&#x27;s more performant (way less memory, similar CPU time) than C# or Java (and certainly all the scripting languages) and contains a massive stdlib for anything you could want to do. It&#x27;s what scripting languages should have been. Anyone can read it just like Python.<p>Rust takes the last 20% I couldn&#x27;t get in a GC language and removes it. Sure, it&#x27;s syntax doesn&#x27;t make sense to an outsider and you end up with 3rd party packages for a lot of things, but can&#x27;t beat it&#x27;s performance and safety. Removes a whole lot of tests as those situations just aren&#x27;t possible.<p>If Rust scares you use Go. If Go scares you use Rust.
    • tracker120 minutes ago
      Can&#x27;t speak for go... but for the handful of languages I&#x27;ve thrown at Claude Code, I&#x27;d say it&#x27;s doing the best job with Rust. Maybe the Rust examples in the wild are just better compared to say C#, but I&#x27;ve had a much smoother time of it with Rust than anything else. TS has been decent though.
    • thinkingtoilet3 hours ago
      It&#x27;s almost comical how often bring up Rust. &quot;Here&#x27;s a fun PHP challange!&quot; &quot;Let&#x27;s talk about Rust...&quot;
      • Xeoncross3 hours ago
        Sorry, but it&#x27;s honestly just a lot of our journeys. Started on scripting languages like PHP&#x2F;Ruby&#x2F;Lua (self-taught) or Java&#x2F;VB&#x2F;C#&#x2F;Python (collage) and then slowly expanded to other languages as we realized we were being held back by our own tools. Each new language&#x2F;relationship makes you kick yourself for putting up with things so long.
        • tracker119 minutes ago
          I don&#x27;t know about that... I like Rust a lot... but I also like a lot of things about C# or TS&#x2F;JS... I&#x27;ll still reach for TS first (Deno) for most things, including shell scripting.
        • thinkingtoilet2 hours ago
          I understand that but there&#x27;s a time and a place. Rust has nothing to do with this. 100% of the people on this site understand that this challenge can be done faster in C, or Rust, or whatever. This is a PHP challenge. Perhaps we could discuss the actual submission as opposed to immediately derailing it.
    • codegeek3 hours ago
      I am not that smart to use Rust so take it with a grain of salt. However, its syntax just makes me go crazy. Go&#x2F;Golang on the other hand is a breath of fresh air. I think unless you really need that additional 20% improvement that Rust provides, Go should be the default for most projects between the 2.
      • Xeoncross3 hours ago
        I hear you, advanced generics (for complex unions and such) with TypeScript and Rust are honestly unreadable. It&#x27;s code you spend a day getting right and then no one touches it.<p>I&#x27;m just glad modern languages stopped throwing and catching exceptions at random levels in their call chain. PHP, JavaScript and Java can (not always) have unreadable error handling paths not to mention hardly augmenting the error with any useful information and you&#x27;re left relying on the stack trace to try to piece together what happened.
  • pxtail5 hours ago
    Side note - I wasn&#x27;t aware that there is active collectors scene for Elephpants, awesome!<p><a href="https:&#x2F;&#x2F;elephpant.me&#x2F;" rel="nofollow">https:&#x2F;&#x2F;elephpant.me&#x2F;</a>
    • t1234s5 hours ago
      Elephpants should be for second and third place. First place should be the double-clawed hammer.
    • thih94 hours ago
      Excellent project. My favorites: the joker, php storm, phplashy, Molly.
  • semiquaver3 hours ago
    Are they just confused about what characters require escaping in JSON strings or is PHP weirder than I remember?<p><pre><code> { &quot;\&#x2F;blog\&#x2F;11-million-rows-in-seconds&quot;: { &quot;2025-01-24&quot;: 1, &quot;2026-01-24&quot;: 2 }, &quot;\&#x2F;blog\&#x2F;php-enums&quot;: { &quot;2024-01-24&quot;: 1 } }</code></pre>
    • daviddoran2 hours ago
      PHP has always escaped forward slashes to help prevent malicious JSON from injecting tags into JavaScript I believe. Because it was common for PHP users to json_encode some data and then to write it out into the HTML in a script tag. A malicious actor could include a closing script tag, and then could inject their own HTML tags and scripts etc.
    • idoubtit1 hour ago
      The weirdness is partly in JSON . In the JSON spec, the slash (named &quot;solidus&quot; there) is the only character that can be written plainly or prefixed with a backslash (AKA &quot;reverse solidus&quot;).<p>See page 4, section 9 of the latest ECMA for JSON: <a href="https:&#x2F;&#x2F;ecma-international.org&#x2F;wp-content&#x2F;uploads&#x2F;ECMA-404_2nd_edition_december_2017.pdf" rel="nofollow">https:&#x2F;&#x2F;ecma-international.org&#x2F;wp-content&#x2F;uploads&#x2F;ECMA-404_2...</a>
    • CapitaineToinon3 hours ago
      That&#x27;s the default output when using json_encode with the JSON_PRETTY_PRINT flag in php.
      • idoubtit2 hours ago
        &gt; That&#x27;s the default output when using json_encode with the JSON_PRETTY_PRINT flag in php.<p>JSON_PRETTY_PRINT is irrelevant. Escaping slashes is the default behavior of json_encode(). To switch it off, use JSON_UNESCAPED_SLASHES.
    • poizan423 hours ago
      &gt; The output should be encoded as a pretty JSON string.<p>So apparently that is what they consider &quot;pretty JSON&quot;. I really don&#x27;t want to see what they would consider &quot;ugly JSON&quot;.<p>(I think the term they may have been looking for is &quot;pretty-printed JSON&quot; which implies something about the formatting rather than being a completely subjective term)
      • ourmandave6 minutes ago
        Pretty JSON not meaning formatting, but more &quot;That was pretty JSON of you.&quot;
  • tveita5 hours ago
    &gt; Also, the generator will use a seeded randomizer so that, for local development, you work on the same dataset as others<p>Except that the generator script generates dates relative to time() ?
  • tomaytotomato1 hour ago
    Tempted to submit a Java app wrapped in PHP exec() :D
  • Retr0id5 hours ago
    How large is a sample 100M row file in bytes? (I tried to run the generator locally but my php is not bleeding-edge enough)
  • csjh2 hours ago
    Obligatory DuckDB solution:<p>&gt; duckdb -s &quot;COPY (SELECT url[20:] as url, date, count(*) as c FROM read_csv(&#x27;data.csv&#x27;, columns = { &#x27;url&#x27;: &#x27;VARCHAR&#x27;, &#x27;date&#x27;: &#x27;DATE&#x27; }) GROUP BY url, date) TO &#x27;output.json&#x27; (ARRAY)&quot;<p>Takes about 8 seconds on my M1 Macbook. JSON not in the right format, but that wouldn&#x27;t dominate the execution time.
    • cess1156 minutes ago
      This log in one of the PR:s claims a 5.4s running time on some Mac.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tempestphp&#x2F;100-million-row-challenge&#x2F;pull&#x2F;47&#x2F;changes#diff-7d100751a9dca9704b546197b4cb78f716a7a142765e75787ce4fcd97758ae52" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tempestphp&#x2F;100-million-row-challenge&#x2F;pull...</a>
  • poizan423 hours ago
    &gt; The output should be encoded as a pretty JSON string.<p>...<p>&gt; Your parser should store the following output in $outputPath as a JSON file:<p><pre><code> { &quot;\&#x2F;blog\&#x2F;11-million-rows-in-seconds&quot;: { &quot;2025-01-24&quot;: 1, &quot;2026-01-24&quot;: 2 }, &quot;\&#x2F;blog\&#x2F;php-enums&quot;: { &quot;2024-01-24&quot;: 1 } } </code></pre> They don&#x27;t define what exactly &quot;pretty&quot; means, but superflous escapes are not very pretty in my opinion.
    • kijin3 hours ago
      They probably mean &quot;Should look like the output of json_encode($data, JSON_PRETTY_PRINT)&quot;. Which most PHP devs would be familiar with.
      • poizan423 hours ago
        It sounds plausible, but they really need to spell out exactly what the formatting requirements are, because it can make a huge difference in how efficiently you can write the json out.
        • maleldil1 hour ago
          It&#x27;s a challenge for PHP programmers. I imagine the relevant people would recognise that format.
  • spiderfarmer6 hours ago
    Awesome. I’ll be following this. I’ll probably learn a ton.
  • wangzhongwang5 hours ago
    [dead]