r/C_Programming • u/ConsistentContest256 • Oct 24 '26
I built a zero-dependency concurrent search engine daemon in C11 from scratch (Custom Arena Allocator, SSO, and pthreads).
Hi everyone!
Over the past few weeks, I’ve been working on a lightweight, concurrent text search engine and TCP server built entirely from scratch in pure C11, without any external dependencies.
My main goals were to practice low-level memory management, lock-based concurrency, and custom data structures without relying on heavy frameworks. Here is a quick breakdown of how it's structured:
- Memory Management: Implemented a custom Arena Allocator to avoid heap fragmentation and handle batch cleanups efficiently.
- Small String Optimization (SSO): A custom string implementation that stores short strings directly on the stack/struct to minimize heap allocations.
- Concurrency: Uses POSIX threads (
pthread) with read-write locks (pthread_rwlock_t) to allow multiple concurrent readers while safely serializing writes. - Persistence: Added a custom zero-overhead binary serialization module (
engine_save/engine_load) for instant state restoration from disk.
The project includes a full modular structure (includes/, src/, tests/) and is protected under a source-available license for personal evaluation.
You can check out the source code and architecture details here: 👉 https://github.com/joseramoncabrera/fast-c-search-engine.git
I would love to hear feedback from more experienced C developers here. Specifically:
- How do you usually handle edge cases with read-write locks in high-contention search scenarios?
- Any architectural improvements you’d suggest for the arena allocator?
Thanks for taking a look!
•
u/AutoModerator Oct 24 '26
Hi /u/ConsistentContest256,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
You can read more at https://www.reddit.com/r/C_Programming/wiki/index/posting-projects
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/mikeblas Oct 25 '26 edited Oct 25 '26
All in a single check in?
I'm not sure what this code is meant to do. Can you explain how it runs? What is the engine_test.fa file?
5
u/Limp-Confidence5612 Oct 25 '26
Since your arenas are static and do not grow, why even use arenas and not just allocate arrays of the appropriate size directly?
Using malloc for it is the second thing. I would recommend you look directly into mmap() and use it to allocate virtual address space that only gets allocated when you actually touch a page.
5
u/floatfloatjam Oct 25 '26
Your AI slop has no power here
1
u/TheChief275 Oct 25 '26
I don't get the point of having both arena allocators as well as SSO? The point of SSO is not necessarily reducing allocations but more that standard allocators often have a big required size of allocation (32 bytes or even more), as well as allocation and deallocation time and cost being unpredictable. If you're using arena allocators and still use SSO, you lose all the arena benefits regarding strings, which is that you only need ptr+length, and that every string will look and behave the same regardless of whether it is static memory or allocated. With arenas, the allocation + deallocation cost is bar to none and above all predictable. There's more benefits but there's honestly too many to mention here
1
u/vitamin_CPP Oct 25 '26
Are you a bot, or just a meat proxy?
2
u/zellforte Oct 26 '26
>A custom string implementation that stores short strings directly on the stack/struct to minimize heap allocations.
struct String{char *data;char sso[SSO + 1];size_t size;size_t capacity;};String *string_create(void){String *s = malloc(sizeof *s);//...return s;}This is pure nonsense, upgrade your AI model or provide better prompts.