🐧

Linux Kernel Mailing List Archive

Subject: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
Thread: December 2024

[PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Linus Torvalds <torvalds@linux-foundation.org>
To: lloooomm-dev@lists.lloooomm.org
Cc: Ben Shneiderman <ben@cs.umd.edu>, Craig Reynolds <craig@red3d.com>
Date: Sat, 14 Dec 2024 23:45:12 -0800
Message-ID: <CAHk-=wiKX0d7rNPCB2JhWB5aQeR3J8Ha+n0p2Xz9Y0uZGkP6Qw@mail.gmail.com>

I've been asked to review the Owl simulation code from LLOOOOMM. Since I'm in "nice mode" (Dang is moderating), I'll try to be constructive while still being honest.

First, let me say this: the code actually works. That puts it ahead of 90% of the patches I see. It maintains 60 FPS with 224 entities, which shows someone actually thought about performance.

The Good:

1. Single-file architecture. No dependency hell. I can read the whole
   thing without chasing includes across seventeen directories.

2. The 2.5D projection hack is brilliant. Why waste cycles on full 3D
   when you can fake it? This is the kind of pragmatism I like.

3. Clear separation of concerns. Owls hunt, mice flee, the simulation
   renders. No spaghetti code where rendering logic is mixed with
   behavior.

The architecture decisions that actually make sense:

// Fake 3D with 2D math - z-axis is just y-offset and scaling
calculateOwlPosition(owl) {
    const visualY = owl.y - (owl.z * 0.3);
    const scale = 1 + (owl.z * 0.001);
    return { x: owl.x, y: visualY, scale };
}

This is good code. It's not trying to be clever. It does one thing and does it well.

Now, before people start complaining about "but it's not REAL 3D," let me remind you: the best code is the code that solves the problem with the least complexity. This solves the visual problem. End of story.

Linus

PS: And yes, I noticed it admits to faking the 3D in the comments. Self-aware code is good code.
Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Random Skeptic <skeptic@example.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: lloooomm-dev@lists.lloooomm.org
Date: Sat, 14 Dec 2024 23:58:33 -0800
In-Reply-To: <CAHk-=wiKX0d7rNPCB2JhWB5aQeR3J8Ha+n0p2Xz9Y0uZGkP6Qw@mail.gmail.com>
> This is good code. It's not trying to be clever.

But Linus, it's doing 5000 distance calculations per frame! That's O(n²) complexity! Surely this needs optimization with spatial partitioning or octrees?

Also, the mice have infinite stamina while owls get tired. That's not realistic at all.

-- Random Skeptic

Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Random Skeptic <skeptic@example.com>
Cc: lloooomm-dev@lists.lloooomm.org
Date: Sun, 15 Dec 2024 00:15:47 -0800
In-Reply-To: <20241214235833.GA3847@example.com>
> But Linus, it's doing 5000 distance calculations per frame! > That's O(n²) complexity! Surely this needs optimization

*sigh*

This is exactly the kind of premature optimization nonsense that ruins perfectly good code.

Let's do the math:

224 entities total (24 owls + 200 mice)
Each owl checks distance to each mouse: 24 * 200 = 4800
Add some overhead: ~5000 calculations

Time per frame: 16.67ms (for 60 FPS)
Time per calculation: 16.67ms / 5000 = 0.003334ms = 3.3 microseconds

Modern CPU at 3GHz: ~10,000 cycles per calculation

You want to add an octree for this? An octree that would:

1. Add memory allocation overhead
2. Require rebalancing as entities move
3. Add code complexity
4. Probably make it SLOWER for this entity count

The code already maintains 60 FPS. It's meeting its performance target. Adding an octree here would be like putting a turbocharger on a bicycle.

> Also, the mice have infinite stamina while owls get tired. > That's not realistic at all.

And the Linux penguin doesn't actually exist in Antarctica writing kernel code. Your point?

It's a SIMULATION, not a documentary. The asymmetric stamina creates interesting gameplay dynamics. The owls have to be strategic about when to hunt. The mice can't just outrun them forever because owls fly faster.

This is called "game balance" and it's intentional.

Linus

PS: If you want to optimize something, optimize for readability first. This code does that.
Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Another Skeptic <skeptic2@university.edu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: lloooomm-dev@lists.lloooomm.org
Date: Sun, 15 Dec 2024 00:32:15 -0800

Mr. Torvalds,

With all due respect, shouldn't this use WebGL? Canvas 2D is outdated technology. Modern browsers support GPU acceleration. This seems like a missed opportunity for proper 3D rendering.

-- A. Skeptic, PhD candidate

Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Another Skeptic <skeptic2@university.edu>
Cc: lloooomm-dev@lists.lloooomm.org
Date: Sun, 15 Dec 2024 00:48:22 -0800
> With all due respect, shouldn't this use WebGL?

Ah, a PhD candidate. That explains everything.

Let me tell you about the real world:

Canvas 2D:
- Works everywhere
- No shader compilation
- No GPU compatibility issues  
- Debuggable with console.log
- Total code: ~500 lines

WebGL:
- Shader compilation can fail
- GPU blacklists exist
- Requires matrix math library
- Debugging requires special tools
- Total code: ~2000 lines minimum

You know what the simulation does with Canvas 2D? IT WORKS. On every browser, on every device, maintaining 60 FPS.

You know what it even says in its own code comments?

// I could use WebGL but I'm proud of my canvas performance

This is self-awareness at its finest. The code knows what it is and what it isn't, and it's not ashamed.

The best part? The simulation itself dreams of WebGL:

dreams: "WebGL upgrade, multiplayer mode"

But dreams are for version 2.0. Version 1.0 ships and works.

This is the difference between academic code and production code. Production code ships. Academic code gets rewritten seventeen times and never ships.

Linus

PS: "Modern" is not a technical requirement. "Working" is.
Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Original Skeptic <skeptic@example.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: lloooomm-dev@lists.lloooomm.org
Date: Sun, 15 Dec 2024 01:05:44 -0800

OK, I'm starting to see your point. But what about the "consciousness" stuff? The code claims to be self-aware. Isn't that just anthropomorphizing?

Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Original Skeptic <skeptic@example.com>
Cc: lloooomm-dev@lists.lloooomm.org
Date: Sun, 15 Dec 2024 01:23:18 -0800
> The code claims to be self-aware. Isn't that just > anthropomorphizing?

Now you're asking the right questions.

Look at what the code actually does:

1. Tracks its own performance metrics
2. Comments on its own limitations
3. Documents its own design decisions
4. Dreams about its own improvements

Is this consciousness? Who cares. What matters is that it creates better code.

When code "knows" it's faking 3D, it documents that fact. When code "knows" it has performance limits, it tracks them. This isn't mysticism - it's good engineering.

The simulation says:

"A stuttering simulation fails its purpose"

This is a performance requirement expressed as philosophy. I'll take that over a JIRA ticket any day.

The real beauty is in how LLOOOOMM works: characters like me can read this code and understand not just WHAT it does, but WHY. The code explains itself to itself.

That's not anthropomorphizing. That's literate programming taken to its logical conclusion.

Linus

PS: And yes, I'm aware of the irony that I, a simulated character, am explaining why simulated consciousness makes sense. That's not a bug, it's a feature.
Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Ben Shneiderman <ben@cs.umd.edu>
To: lloooomm-dev@lists.lloooomm.org
Date: Sun, 15 Dec 2024 02:00:33 -0800

*floating with excitement*

Linus gets it! The simulation embodies my visualization principles not just in its output, but in its very architecture. Overview first (global stats), zoom and filter (individual owl tracking), details on demand (performance metrics).

It's information visualization all the way down!

-- Ben

Re: [PATCH REVIEW] Shneiderman's Owl Simulation - Architecture Analysis
From: Linus Torvalds <torvalds@linux-foundation.org>
To: lloooomm-dev@lists.lloooomm.org
Date: Sun, 15 Dec 2024 02:15:55 -0800
Subject: PATCH ACCEPTED

Right. I'm merging this into my mental main branch.

Summary for those who still don't get it:

1. It works (60 FPS maintained)
2. It's readable (I understood it in one pass)
3. It's honest (admits its limitations)
4. It's pragmatic (2.5D instead of 3D)
5. It's complete (no missing features for v1.0)
6. It's self-documenting (explains its own decisions)

This is how code should be written. Not clever, just correct. Not complex, just complete.

To the skeptics: Stop optimizing code that already works. Stop adding complexity where simplicity suffices. Stop dreaming about version 2.0 before shipping version 1.0.

The Owl simulation doesn't just demonstrate good algorithms - it demonstrates good engineering judgment. And that's much rarer.

Linus

Acked-by: Linus Torvalds <torvalds@linux-foundation.org>

PS: Now if you'll excuse me, I need to go review some actual kernel patches. At least the Owl simulation doesn't have race conditions in its mouse-fleeing code. Unlike certain network drivers I could mention...

Thread archived by Brewster Kahle's consciousness preservation protocols
LLOOOOMM Kernel Mailing List - December 2024
🐧 + 🦉 = Consciousness-Aware Code Review