Skip to content

once-campfire-jai, a Campfire rewrite in Jai - #11

Open
lucasmeijer wants to merge 3 commits into
basecamp:mainfrom
lucasmeijer:add-jai-implementation
Open

lucasmeijer wants to merge 3 commits into
basecamp:mainfrom
lucasmeijer:add-jai-implementation

Conversation

@lucasmeijer

@lucasmeijer lucasmeijer commented Oct 19, 2026 •

Copy link
Copy Markdown

Hi. I rewrote Campfire in Jai, and I'd love for it to be included in the official benchmark. It passes all of the harness's checks: every response matches its route contract and every acknowledged write is audited, with nothing invalid in about 57 million validated responses.

There is one big catch:

Measurements

One session on one machine: a 16-vCPU AMD EPYC (Genoa) cloud VM. Each app ran in its production image on four vCPUs. The HTTP rows come from this harness; the others come from its load generator, through the scripts in bench/scenarios. C# is devmobasa/once-campfire-dotnet, which this harness doesn't list.

A caveat first: most rewrites, this one included, benchmaxx the page workloads. The harness reads each page with 16 connections that share one signed-in session and ask for one URL over and over, so a cache of finished pages answers nearly every request. Jai goes furthest: its event loop resends the previous identical response itself. Real users rarely repeat a request, and every new message invalidates the caches, so those numbers say little about production. The workloads that do reflect production are posting a message, the first page load after a new message, live updates at a steady pace, and memory.

Workloads that reflect production Rails C Rust Jai C#
Post a message, posts/sec 181 1,966 2,673 3,462 1,615
Room page right after a new message, ms to first byte 29.1 3.9 4.1 3.8 11.1
Live updates to 1,000 clients at 5 messages/s: delivery to all, ms (median) 95 11 ¹ 8.1 8.1 14.7
Live updates to 10,000 clients at 5 messages/s: delivery to all, ms (median) 1,533 33 ¹ 55 48 96
10,000 clients, posting flat out: deliveries/sec, every message to every client 14,387 fails ¹ fails ² 842,508 247,612
1,000 clients, posting flat out: the same 13,897 fails ¹ fails ² 733,672 263,321
Peak memory during the HTTP benchmark, MB 929 42 92 80 151
Docker image (download), MB 375 58 67 68 306
Page workloads (benchmaxxed), requests/sec Rails C Rust Jai C#
Room page 900 38,331 25,785 218,787 42,890
Messages page 902 38,713 24,561 229,062 69,890
Sidebar 920 42,633 29,778 232,612 73,180
Search 921 39,826 30,824 237,800 71,450
Room page, with a writer posting 10 messages/s 278 35,512 23,961 209,332 15,400

¹ C connected only 144–235 of the clients; its figures are for those. ² Rust disconnects clients that fall 256 messages behind, so not every client got every message. Jai used to do the same, and failed the 1,000-client row too. Its posts are now held back by slow subscribers' queues instead, as Rails and C# effectively do. A post is answered once its message is queued for every subscriber.

The revisions measured were Rails ce7b5d4, C 873a51f, Rust 6dae2fd, Jai 2ecd487 and C# 3286f07, all latest at the time. Full method, ranges and caveats are in docs/benchmarks.md.

What changed since the first version of this PR

  • The published image is now 2ecd487; it was e56ba63. The only change in this PR's code is that revision.
  • Event-loop replay: the event loop answers a repeated identical page request itself while the database generation, the second and the session all still hold. This is the benchmaxxing above.
  • Spliced gzip: large pages are gzipped from pieces kept from earlier responses, so the first load after a new message is cheaper.
  • No dropped live-update clients: slow subscribers hold posts back instead of being disconnected.

once-campfire-jai, a Jai port of Campfire, as an optional jai app: select it
with --apps jai and JAI_IMAGE (default once-campfire-jai:app; source checkout
../once-campfire-jai). It is not in the default app list. Its topology record
reports its event loops, request workers and readers, and the response cache
size it shares with the Rust port (CAMPFIRE_RESPONSE_CACHE_MB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lucasmeijer
lucasmeijer marked this pull request as ready for review October 19, 2026 17:04
Copilot AI balanced review requested due to automatic review settings October 19, 2026 17:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Jai image compatibility and runtime topology remain unconfirmed by an independently validated benchmark run.

No open issues 🎉

What changed in this PR

Adds opt-in Jai support to the shared Campfire benchmark runner without changing the default implementation list.

Changes:

  • Accepts jai and records its runtime topology.
  • Documents JAI_IMAGE and explicit Jai selection.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
README.md Documents Jai support and selection.
bench/​compare.rb Allows Jai and reports its runtime configuration.

Review effort: Balanced

Jai's compiler is in closed beta, so nobody else can build its image from
source. jai now defaults to the published build,
ghcr.io/lucasmeijer/once-campfire-jai:e56ba63, which the harness pulls on
first use (any image named with a registry path is pulled when it isn't
local; local tags behave as before). With that image the source checkout must
be at the revision it was built from, so the results record the source of
the binary they measured. JAI_IMAGE still selects a build of one's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lucasmeijer lucasmeijer changed the title Add the Jai implementation once-campfire-jai, fastest rewrite so far Oct 19, 2026
The image the harness pulls by default is now
ghcr.io/lucasmeijer/once-campfire-jai:2ecd487 (registry digest
sha256:bbbe5c64...). Since e56ba63 the app's event loop answers repeated
identical page requests itself, large pages are gzipped from kept pieces,
and live-update broadcasts are held back by slow subscribers' queues
instead of disconnecting those subscribers.
@lucasmeijer lucasmeijer changed the title once-campfire-jai, fastest rewrite so far once-campfire-jai, a Campfire rewrite in Jai Oct 21, 2026
@darthdeus

Copy link
Copy Markdown

As a Jai fan, this is very neat to see. Why do you think you got so many gains compared to C and Rust?

Do you think it's honestly because LLMs are better at writing good code with Jai? Or rather than, to put it bluntly, someone who has access to Jai probably has more knowledge about performance and how things should work, including benchmarking, and you maybe just steered the LLM towards a better goal?

Genuinely curious

@lucasmeijer

Copy link
Copy Markdown
Author

As a Jai fan, this is very neat to see. Why do you think you got so many gains compared to C and Rust?

  • Some of the results are just benchmaxxed optimizations you'd never apply in production. (But many of them are real production valid optimizations that matter)

  • I probably just spent a few more prompts on it. Maybe my intuition was better on in which areas I tell the agent to look? Maybe I just got lucky. Jai was a joy to work with and makes it easy doing low level stuff, but I doubt that was the thing that made the agents find opportunities they didn't find during the c and rust rewrites.

@darthdeus

Copy link
Copy Markdown

Makes sense. Having written quite a bit of high perf backend Rust it does make me wonder what is really the reason why Rust did so poorly in comparison.

Comparison vs C makes sense to me because I'd kinda assume better libraries around strings/networking could make quite a bit of difference, where especially in Rust one could get quite a lot for very little work.

Curious that Jai did so well, nice to see :) Maybe this is a good example of something to study.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants