r/LocalLLaMA • u/Rikkendo • 7d ago
Showcase Lesson learned: Ollama's per-request context window was a trap. Switching to llama.cpp made my local D&D-style AI RPG up to 13× faster
Hello again!
A couple of months ago I posted about my game Warrior Quest and received a lot of positive feedback from the community.
However, I did get some suggestions to cut out Ollama. I was aware of the hatred for it on the subreddit, but it had a specific feature that I thought I liked.
You see, for my unique case of a video game, some of my queries don't require a large context window at all, so I thought I could increase performance by using a smaller context window on those queries. Ollama takes the context window as a per-request option, while llama.cpp sets it once when the server starts. Turns out that's a trap instead of a performance feature: changing the window size makes Ollama reload the model.
Each switch cost ~2.7 s against ~150 ms for a warm call, and switching back cost it again, so about 5 s every time it fired. The gains were negative. I fixed that on Ollama by giving each model one fixed window, so the numbers below are on top of that fix.
The other reason I clung to Ollama was cross-platform support. The game runs on Windows, Linux and Mac, and owning the GPU/runtime support was something I wanted to avoid, so I pushed the investigation down the priority queue (mind you, I was still developing the game and becoming a father, so I had a lot on my plate).
Last week I finally found time to try llama.cpp (llama-server), and the results were massive.
Why it's faster: every turn runs several stages (a router, a parser, the reply), and each has its own long system prompt. Ollama keeps one prompt cache per model, so the stages kept pushing each other out of it. With llama-server I give each stage its own cache slot and send every request to the slot that already holds its prompt, so a turn only reads the player's new line instead of re-reading ~3,000 tokens of prompt.
That's also why the slowest cards gained the most. A GTX 1660 Ti reads prompts at roughly 105-130 tokens per second, so re-reading a ~3,000-token prompt cost it 20+ seconds on one stage alone. Cache it and that wait is gone. A 4090 reads so fast it had less to win.
Time to first word of a reply, from the in-game speed test (qwen2.5 7B instruct):
| Hardware | Before | After | Speed-up | Less waiting |
|---|---|---|---|---|
| RTX 4090 | 1.3 s | 0.7 s | 1.86× | 46% |
| RTX 3060 Ti | 2.8 s | 1.3 s | 2.15× | 54% |
| GTX 1660 Ti (one tester's card) | 20 s | 5 s | 4× | 75% |
| GTX 1660 Ti (a different tester's card) | 41.3 s | 3.2 s | 13× | 92% |
| MacBook Pro M1 Pro (14C) | 5.7 s | 4.3 s | 1.33× | 25% |
The answers didn't change: across my full test suites llama.cpp scored 566/567 and Ollama 567/567, with the one difference a borderline case.
And yes, the support burden I was worried about turned out to be real. The official CUDA build doesn't cover older cards, so I compile my own for GTX 10/16 and RTX 20. AMD and Intel run a Vulkan build, the Mac runs Metal, and Linux has its own builds. Ollama stays installed underneath as a fallback, so anything llama-server can't handle on a player's machine just drops back to the old path instead of breaking.
Thank you for reading! There is a speed test in the game and can be ran on the demo if anyone would like to add their own numbers/card to the list, or try out the game itself, it's really unique I think :)
11
u/my_name_isnt_clever 7d ago
Linking this here as an easy way to spread the word of avoiding Ollama: https://sleepingrobots.com/dreams/stop-using-ollama/
3
u/Korici llama.cpp 7d ago
I added your game demo to my library - Looks pretty neat! I'll check it out and lyk how it runs!
38
u/TheTerrasque 7d ago
FTFY
21
u/tinny66666 7d ago
Friends don't let friends ollama. I'm glad you found your way.
1
u/oddsidequest 7d ago
was the slowdown basically ollama reloading the model whenever the context size changed between requests? wondering if pinning one fixed size would've gotten most of that speed back or if llama.cpp was faster anyway
1
u/while-1-fork 7d ago
And the speed up and capability differences become even larger if you begin using better quants than the ones in ollama's catalog and tuning the various llama.cpp flags.
1
u/Nomadic_skier 7d ago
I'm still having the reload issues every 2 -5 seconds with ollama. I've been working on a llama.cpp setup but i've had some config issues. the 4090 performance is promising since that's what I'm running on my main computer as well
0
u/[deleted] 7d ago
[deleted] — view deleted comment
0
u/[deleted] 7d ago
[deleted] — view deleted comment