Skip to content

Kotlin spike - #1

Open
MDA2AV wants to merge 2 commits into
mainfrom
kotlin-spike
Open

Kotlin spike#1
MDA2AV wants to merge 2 commits into
mainfrom
kotlin-spike

Conversation

@MDA2AV

@MDA2AV MDA2AV commented Sep 7, 2026

Copy link
Copy Markdown
Owner

No description provided.

… over Panama

ioma_route_ffi registers a plain C function pointer with a flat, padding-free
request (ten 8-byte fields) and reply (32 bytes) so any binding can lay them
out. Such a handler must not run on a coroutine's 64 KB stack (a JVM
bounds-checks and walks the thread's real stack), so the coroutine parks with
await_call and the loop runs it on the worker's own thread stack, then resumes
the coroutine with the reply. Every resume goes through run_coro, which
services those calls. Middleware still wraps foreign endpoints.

playground/kotlin: Server.kt loads libioma.so through java.lang.foreign, turns
two Kotlin functions into upcall stubs, registers them and hands the main thread
to ioma_run. Allocation-free on the hot path; reads the request and writes the
reply straight in C memory.

Verified: a C test asserts the handler lands on the 8 MB thread stack; sums,
chunked bodies, 404 and the fragmentation sweep pass from Kotlin. On 4 pinned
cores the Kotlin handler does ~1.18M req/s vs ~1.26M native (JDK 26.0.2.1).

Claude-Session: https://claude.ai/code/session_013wYnJvEFUjKEpGLkyTLt9P
One upcall dispatcher serves every route (the route index rides in userdata),
per-thread Request/Reply wrappers hide the offsets and reinterprets, and the
app is just routes with lambdas. Same throughput as the hand-rolled version
(~1.17M req/s on 4 cores, JDK 26); sums, chunked, 404 and the fragmentation
sweep pass.

Claude-Session: https://claude.ai/code/session_013wYnJvEFUjKEpGLkyTLt9P
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.

1 participant