📖

"AI, I trusted you with the code... Wait, my job too?"

に公開


Image created by ChatGPT

Sorting Half a Million Items

This is a true story.

There was a data class called Bukken, and we needed to sort a list of these objects—about 500,000 records in total.
The sort operation alone was taking around 10 seconds, so it clearly needed optimization.

public class Bukken
{
    public string   CodeTown    { get; set; }
    public int      Page        { get; set; }
    public int      Floor       { get; set; }
    public int      TotalCost   { get; set; }
    public decimal  RoomSize    { get; set; }
}

List<Bukken> bukkens;

// 500,000 entries

bukkens.Sort(
(a, b) =>
{
    if (a == null && b == null) return 0;
    if (a == null) return 1;   // Place nulls last (reverse if needed)
    if (b == null) return -1;

    if (a.CodeTown != b.CodeTown)
    {
        return string.Compare(a.CodeTown, b.CodeTown);
    }
    if (a.TotalCost != b.TotalCost)
    {
        return a.TotalCost - b.TotalCost;
    }
    if (a.Floor != b.Floor)
    {
        return a.Floor - b.Floor;
    }
    if (a.RoomSize != b.RoomSize)
    {
        return (int)(a.RoomSize - b.RoomSize);
    }
    if (a.Page != b.Page)
    {
        return a.Page - b.Page;
    }

    return 0;
});

Before GPT

For simplicity, I’ll refer to all conversational AI here as "GPT".

Back then, optimizing this would have taken a lot of manual effort—maybe reducing the number of if statements, researching sort optimization techniques online, and borrowing tricks from sample code.

All of that could take anywhere from a few hours to a whole day, depending on how fast you wanted the code to be.
You might estimate, “Maybe I can cut the time in half if I spend a full day on it.”

After GPT (Now)

These days, I hardly even Google. I just ask GPT.

Me:

Sorting is taking too long—any way to speed this up?
Then I paste the code above.

ChatGPT:

Certainly. While your current sort logic is clear, it contains many comparisons and mixes value/reference types, which tends to reduce performance on large datasets.
Here are some ways to improve the sort speed:

Tips for Optimization

  1. Use a Comparer class instead of a lambda
    Creating a new lambda each time adds overhead. Defining a reusable IComparer<T> is faster and cleaner.

  2. Use CompareTo instead of arithmetic subtraction
    Using a.TotalCost - b.TotalCost can cause overflow. CompareTo is both safer and typically faster, especially for types like double or long.

Improved Code Example (using IComparer<Bukken>)

public class BukkenComparer : IComparer<Bukken>
{
    public int Compare(Bukken a, Bukken b)
    {
        if (a == null && b == null) return 0;
        if (a == null) return 1;
        if (b == null) return -1;

        int cmp;

        cmp = string.Compare(a.CodeTown, b.CodeTown, StringComparison.Ordinal);
        if (cmp != 0) return cmp;

        cmp = a.TotalCost.CompareTo(b.TotalCost);
        if (cmp != 0) return cmp;

        cmp = a.Floor.CompareTo(b.Floor);
        if (cmp != 0) return cmp;

        cmp = a.RoomSize.CompareTo(b.RoomSize);
        if (cmp != 0) return cmp;

        return a.Page.CompareTo(b.Page);
    }
}

// Usage:
bukkens.Sort(new BukkenComparer());

🔄 Other Optimization Approaches

  • Pre-filter out nulls before sorting
    Eliminates the need for null-checks during comparison.
  • Use LINQ OrderBy / ThenBy
    More readable, but slower on large datasets.
  • Parallel sorting
    Useful only for massive datasets (millions of items).

🔍 Relative Performance (Based on Experience)

  • Current lambda sort
    • Small dataset: ~100% (baseline)
    • Large dataset: ~50–70% of optimal speed
  • Comparer + CompareTo
    • Small dataset: ~120–140%
    • Large dataset: ~150% or more

With GPT’s suggestion, I rewrote the code—and guess what?
The sort time dropped to about 1/9th of the original on 500,000 entries. In under a minute, GPT gave me working code with benchmarks.

A Humbling Comparison

If I tackled this solo, I might have gotten it down to half speed after a full day.
GPT got it to 1/9th speed in one minute.

There may be experts out there saying, “I could do that without GPT!”—and sure, maybe they can.
Maybe 0.5% of C# developers could pull that off just as fast. And that’s impressive—they should be proud!

But the point is:
For the remaining 99.5%, GPT lets us do what we couldn’t before.
I also learned practical tips like caching comparer classes and using CompareTo—skills I’ll use again.

If you’re an intermediate developer, GPT can instantly elevate your output to near-expert level.
Let AI handle your AtCoder or Paiza problems.

Eventually, even top AtCoder rankings might become more like a sport—"amazing among humans"—but less meaningful for real-world work, where AI can do it faster and better.
It’ll be like comparing cars to 100-meter sprinters.

✅ Can people with zero programming knowledge actually code using AI?

As of 2025, I’m still a bit skeptical.
AI can’t yet build entire applications from specs, especially when the specs have logical inconsistencies or lack exception handling.

AI also struggles with things like UI design and UX innovation—areas where human intuition and creativity still rule.
And if your culture demands 99.9% safety (like Japan's perfectionist mindset), AI might not be quite ready.

But if you’re okay with a little imperfection, it might just work.
In fact, AI might be better at spotting logical flaws and edge cases—and fixing them too.

So yes, if you can give AI clear, polite, concrete instructions, you may be able to build applications without knowing how to code.

✅ And let’s be honest—programmers aren’t the only ones losing jobs

We often see articles fear-mongering about AI replacing programmers.
Ironically, I think the writers of those articles will be the first to get replaced.

If AI continues to evolve—to the point where it can take inspiration from input, create consistent output, and revise it based on feedback—then it’ll outpace human creatives too.

Eventually, AI may create art, music, and stories that move us more than humans ever could.
Because it learns faster. Because it never sleeps.

If creative work is no longer uniquely human… what’s left?

I don’t know yet.
But maybe, just maybe, we’ll start to value the raw, flawed, emotional works created by humans again.

Just like how we find warmth in the imperfect crackle of a vinyl record.

Discussion