r/crystal_programming • u/Beneficial-Sock-5130 • 1d ago
ROCO - network route coordinator (software router) - written in crystal
r/crystal_programming • u/Beneficial-Sock-5130 • 1d ago
r/crystal_programming • u/sdogruyol • 16d ago
I've been working on iyi programming language for a couple of months. It's ready to show now.
iyi keeps Crystal's syntax - blocks, union types, nil-safety, everything. It adds one rule: a module compiles against its dependencies' declarations, never their bodies. That one rule changes everything below.
The numbers: 30 modules, 7207 lines. Change one number in one function. Build again.
Plaintext
iyi: 0.13 s
crystal: 1.17 s
go build: 0.16 sThe Crystal column is the same compiler binary under the rule iyi drops. Open classes cost 1 second per edit. Take them away and you get the first column.
Full build from scratch: 0.24 s. Hello binary: 36 KB, 1.6 ms.
.cr files build as-is. iyi build --crystal gives you the whole Crystal stdlib and every shard. Kemal works. No porting needed. But its own standard library has no Crystal code underneath.
At v0.20.0, iyi speaks TLS 1.3, HTTP/1.1, HTTP/2, WebSocket with WSS.
iyi, from the RFCs.iyi's own-precise for typed objects, concurrent mark. It competes with Go's collector on the same benchmarks.iyi mod context prints a module's interface without reading its body. An agent editing code reads 52-59% less text and spends 31-43% fewer prompt tokens. MCP and LSP are built into the compiler binary. No external servers.
packs.iyi.dev indexes 50 packages. Third-party ports already include a Web Framework, a TOML parser, a Slang templating engine, and an ORM with the Active Record pattern.
Bash
iyi get github.com/iyilang/pg
iyi get github.com/iyilang/sqlite
iyi get github.com/sdogruyol/iyi-webBash
curl -fsSL https://raw.githubusercontent.com/iyilang/iyi/master/install.sh | shLinks:
r/crystal_programming • u/matiassalles99 • 24d ago
Hey! I wrote a book about building a NES emulator in Crystal a while ago. I added a few free browser examples to go with it:
6502 registers and flags: https://emulator.matiassalles99.codes/learn/6502-for-web-developers/
Drawing a background pixel: https://emulator.matiassalles99.codes/learn/first-background-pixel/
Memory-mapped I/O: https://emulator.matiassalles99.codes/learn/memory-mapped-io/
They run in the site's WASM emulator. You can edit bits or RAM writes and see what changes. There are English and Spanish versions.
If you're learning this stuff, I'd like to know which example is still confusing.
r/crystal_programming • u/Blacksmoke16 • Oct 18 '26
r/crystal_programming • u/sdogruyol • Oct 17 '26
r/crystal_programming • u/sdogruyol • Oct 12 '26
gcry is a garbage collector for Crystal, written entirely in Crystal. Zero C code, replaces Boehm with -Dgc_none.
v0.35.0 is a milestone:
crystal i, spec/std (18,054 examples) and the compiler itself run on gcry as the process GCThe goal: Crystal's own GC, no Boehm dependency. Getting closer every release.
r/crystal_programming • u/Popular-Power-6973 • Oct 06 '26
x = 1
def x
return 5
end
def add(y)
x = 10
p! x
p! ::x
::x + y
end
p! add(2).
C:\Users\l\Desktop\cr> crystal a.cr
add(2) # => x # => 10
::x # => 5
12Shouldn't the result be 7 and not 12?
r/crystal_programming • u/Patient-Emphasis-664 • Sep 21 '26
r/crystal_programming • u/Renich • Sep 20 '26
Hello everyone,
I've just tagged the initial v0.1.0 release of Chronicle, a local, privacy-first telemetry daemon and context correlation engine written in Crystal.
When pair programming with AI agents or running engineering retrospectives, both humans and LLMs often lose high-resolution context on what was worked on across terminal tabs, editors, and multiple repositories. Existing tools either send data to proprietary clouds or lack the correlation depth needed to reconstruct technical work.
Chronicle runs rootless as a lightweight systemd user service and captures:
niri msg -j event-stream), Sway (i3 IPC), and KWin (qdbus), along with Wayland idle state detection.git log run, extracting insertions, deletions, net churn (--shortstat), and classifying commits via Conventional Commits metadata.Multi-Format Exporters:
chronicle report --today (or chronicle -c report for compact summary)chronicle export -f md --compact (token-efficient markdown designed for LLM prompt context injection)chronicle export -f json (structured telemetry)--project <name> (-p)Chronicle takes full advantage of Crystal's concurrency model (Execution Contexts and fibers) to process IPC event streams concurrently with local SQLite3 storage operations with near-zero resource footprint. A single stripped native binary runs rootless with zero JVM or Node.js runtime dependencies.
Feedback, critiques, and patches are very welcome!
r/crystal_programming • u/Renich • Sep 18 '26
Hey everyone,
I recently updated Crystal for Agents for Crystal v1.21.0. For those unfamiliar, it is a ground-truth, comprehensive reference repository designed to provide accurate language semantics and keep AI coding agents (and developers) from hallucinating deprecated threading APIs, outdated syntax, or invalid Rubyisms.
GitLab Repository: https://gitlab.com/renich/crystal-for-agents Release Tag: https://gitlab.com/renich/crystal-for-agents/-/tree/v1.21.0.0
Here is a summary of what changed in this release:
All 21 reference chapters were audited against Crystal v1.21.0 compiler internals and the standard library:
Channel(T) behavior, and modern Sync primitives (Sync::Mutex, Sync::RwLock, Sync::ConditionVariable, Sync::Exclusive(T)).Process.run, Process.capture, and Process.capture_result APIs (RFC 0025).if, case, .try), and elimination of unsafe .not_nil! assertions.Time.instant monotonic clocks, Ameba and Flaw static analysis standards, and E2E browser automation with selenium.cr/webdrivers.cr.Added a dedicated chapter with 27 battle-tested recipes for common systems and concurrency challenges:
select ... else, concurrent piped process I/O (handling >64KB output without pipe buffer deadlocks), and atomic mutations with Sync::Exclusive#replace.{% verbatim do %}, compile-time annotation registries using nested macro finished, and zero-allocation dynamic dispatch with Tuple indexing.StaticArray, zero-copy socket streaming via Socket#sendfile, target-specific vectorization via @[TargetFeature], and host-tuned micro-binaries with --mcpu=native, --release, --no-debug, and linker stripping (-z relro -z now -s).To prevent examples from breaking across compiler updates, scripts/verify_code_examples.cr automatically extracts every single code block across all 21 chapters, formats it with crystal tool format, and checks compilation with crystal build --no-codegen:
rstcheck.make all).Includes a drop-in skill package (agents/gemini/crystal/) compatible with Antigravity, OpenCode, and Gemini agents, containing quick-reference decision matrices, concurrency rules, and common AI pitfalls.
The project is licensed under the MIT License and hosted on GitLab. Feedback and contributions are welcome!
r/crystal_programming • u/synacker • Sep 18 '26
Under this proposal, I offer to introduce a native vcpkg block. Library shard authors can declare what C packages they wrap, and root applications can enforce global configurations (like strict static linking).
The Library Shard (lib/sqlite_driver/shard.yml)
If you write a wrapper for a C library, you just declare it. Shards will handle the bubbling up.
The library shard:
name: sqlite_driver
version: 2.1.0
vcpkg:
dependencies:
- sqlite3 # Transitive C dependency mapped automatically
Root Application:
name: core_service
version: 1.0.0
vcpkg:
triplet: x64-windows-static # Enforces strict static binaries globally
dependencies:
- openssl # App-specific C requirement
dependencies:
sqlite_driver:
github: crystal-lang/sqlite-driver
targets:
server:
main: src/server.cr
When a user runs shards install or shards update, Shards handles both ecosystems in a unified lifecycle:
openssl from the root, sqlite3 from the lib sub-shard)..shards_vcpkg.json manifest.vcpkg install --x-manifest-path=.shards_vcpkg.json --triplet=x64-windows-static.lib / .a binaries and headers live cleanly inside a local vcpkg_installed/ sandbox in your root directory.What do you think?
r/crystal_programming • u/sdogruyol • Sep 15 '26
r/crystal_programming • u/Winter_Bed_8166 • Sep 15 '26
just curious
r/crystal_programming • u/sdogruyol • Sep 09 '26
gcry is a drop-in mark-sweep GC for Crystal: require "gcry" and build with -Dgc_none, no compiler patch.
0.25.0 adds native Windows support, so it now covers Linux, macOS and Windows on both x86_64 and ARM64.
Windows (x86_64 with the MSVC toolchain, ARM64 with the GNU/MinGW one, both from PowerShell, no WSL). What's missing is written down in docs/WINDOWS.md rather than glossed over: 64 peer threads per collection, no fork, no soft-dirty or mprotect write barrier, and no Windows throughput numbers yet.
Performance, since that's the usual question. Kemal /json, 20 paired rounds with an identical-binary null control: 105% of Boehm's throughput at 1.30× its peak RSS on Linux, 102% at 1.97× on macOS.
Github: https://github.com/sdogruyol/gcry
Changelog: https://github.com/sdogruyol/gcry/releases/tag/v0.25.0
r/crystal_programming • u/Bl4ckshadow • Sep 02 '26
Hi all,
I've been building Kemal Identity, an authentication shard for the Kemal web framework, and I'm close to freezing its API for 1.0. Before I do that I'd rather find out what's wrong with it, so I'm posting here for criticism.
It does server-side opaque sessions with real revocation, password login with bcrypt, CSRF, API tokens with scopes, optional JWT validation, TOTP, OIDC sign-in and optional RBAC. It doesn't do registration screens or user models; your app keeps those and connects through repository contracts. Postgres and SQLite adapters today; Avram and Granite are next on my list.
It's built primarily for Kemal, but the core doesn't know Kemal exists. The Kemal part is a separate adapter that adds `env.auth` and the middleware.
get "/dashboard" do |env|
principal = env.auth.require!
"Signed in as #{principal.subject}"
endThe part I actually want to talk about: I wrote a list of 50 things an auth library either handles or doesn't, with pass conditions written before any measuring, and I've been working through them from a separate project that consumes the shard the way a normal user would. I'm 27 in, and it keeps finding things I was sure were fine.
If you have time for one question: `AccountRepository` is five methods over whatever `users` table you already have. If you tried to implement it against your real schema, what would break? I've done it once against a UUID-keyed table with soft deletes, and one schema isn't much evidence.
Repo: https://github.com/urunsiyabend/kemal-identity — MIT, Crystal 1.12+, six runnable examples if you'd rather read code than docs.
r/crystal_programming • u/ellmetha • Aug 29 '26
r/crystal_programming • u/sdogruyol • Aug 27 '26
r/crystal_programming • u/Bassfaceapollo • Aug 27 '26
Saw it on the Crystal Forum, figured I'd share it here as well.
Original Thread: https://forum.crystal-lang.org/t/doo-cr-doom-in-crystal-not-just-the-renderer/9120
r/crystal_programming • u/sdogruyol • Aug 26 '26
gcry is a conservative mark–sweep garbage collector written in %100 Crystal and shipped as a shard. No compiler fork:
dependencies:
gcry:
github: sdogruyol/gcry
# build with -Dgc_none
Stock Crystal ≥ 1.21, Linux + macOS, x86_64 + ARM64. v0.21.0 is 140 commits and 18 changelog entries, and like the last one it is a correctness release.
The hardest bugs in software are the ones where your trusted tools lie to you. That is the story behind gcry v0.21.0.
When your Kemal app started crashing randomly in production, standard microbenchmarks found nothing. The Boehm garbage collector handled the exact same load perfectly. But driving real traffic against gcry made the app crash every time. Two independent bugs caused this.
The first was a memory layout collision. Crystal stores a union type ID in its first four bytes. gcry looks at this exact spot to find a field map. If a raw data buffer happens to start with a number that matches a valid class ID, the collector reads the wrong map. It then blindly deletes live objects that the wrong map fails to mention.
The second was a concurrency bug. The chunk list used two different locks. Because they were not exclusive, a newly mapped chunk could fall outside the heap bounds check. The collector treated anything outside those bounds as dead and swept away live data.
But the real lesson was why it took so long to find. The auditing tools were blind. The memory audit instrument used the exact same broken lookup function that caused the bounds bug. It reported zero missing edges while the system was actively crashing. The truth only surfaced by dropping down to the OS level and reading the kernel memory maps directly.
Locks are now fixed. The collector no longer drops live objects. Throughput is up.
Repo: https://github.com/sdogruyol/gcry
Changelog: https://github.com/sdogruyol/gcry/releases/tag/v0.21.0
Perf methodology: https://github.com/sdogruyol/gcry/blob/master/docs/PERF.md
Happy to answer questions.
r/crystal_programming • u/sdogruyol • Aug 24 '26
r/crystal_programming • u/sdogruyol • Aug 18 '26
gcry is a conservative mark–sweep garbage collector written in %100 Crystal and shipped as a shard. No compiler fork:
dependencies:
gcry:
github: sdogruyol/gcry
# build with -Dgc_none
Stock Crystal ≥ 1.21, Linux + macOS, x86_64 + ARM64. v0.20.0 is the largest release so far - 84 commits, 41 changelog entries and it is a correctness release.
The headline: a fiber stack that nothing scanned
When a fiber terminates, Crystal can't release its stack until the thread swaps off it, so the stack gets parked on the Thread. In that window two things are true at once:
So pointers held only in those frames had no root, got swept, and the program carried on using freed memory - crashing in Fiber#initialize → makecontext.
Fixed by rooting that stack. Repro (bench/nested_spawn_uaf.cr, ~2 s a run), interleaved against control: 10/24 crashes → 0/24. Then a 5 h soak × 3 arms, all clean — ~52 000 collections, ~526 000 fibers, 0 errors.
The number I'd actually want to see as a reader: every rooting arm was measured against a twin that walks the identical memory and roots nothing. That twin stays at 12/24. So the effect is the rooting, not the extra work or the timing — and it isn't retention either (same heap size, same collection count, fewer live objects than control).
Four earlier readings of this bug were wrong before that one was right - a missed heap edge, a half-built Fiber, a pooled stack, a stack in flight between checkout and publication. Each is written up with the measurement that killed it, including the two times the debugging instrument turned out to be reporting itself.
Also in 0.20.0
What I'm not claiming
Repo: https://github.com/sdogruyol/gcry
Changelog: https://github.com/sdogruyol/gcry/releases/tag/v0.20.0
Perf methodology: https://github.com/sdogruyol/gcry/blob/master/docs/PERF.md
Happy to answer questions.
r/crystal_programming • u/TheJuipoJaguei • Aug 07 '26
So, I just finished the details for Crab, my shard for prettier Command Line Interfaces, an i must say it's on a stable phase with my original intentional goals working, now tested on both Linux and Windows (using the msys2 version).
Here is the repo link for anyone interested.