reckless-utf8
2026-11-29
GC-friendly UTF8 encoder/decoder

1Reckless UTF-8
Encoding and decoding UTF-8 without memory allocation.You can fill an octet buffer you already hold with the bytes of a string, or fill a string buffer you already hold with the characters taken from a run of octets.
Validation of octets is done in place. No new storage is made on the heap. Bound errors and ill-formed sequences are signalled by named conditions of their own.
2Why a new library
trivial-utf-8 does not keep to the full Unicode standard; over-long forms and otherbad shapes slip through. babel is sound in its checks, yet on every decode it mustgive back a fresh string. That puts strain on the garbage collector. There aren't anyalternatives that conforms to the RFC 3629.That Babel returns fresh strings sound trivial in many case, but in my system I have
measured in my web socket code (using the library wscli) that about 8% of all my GC
garbage come from Babel. SBCL and LispWorks the GC stops the world, and each stop can
be about 50ms, which is unacceptable for many real-time work. By using reckless-utf8
instead I shaved off about 4 ms almost for free.
Allegro alone among the common systems has ZGC, but vendor lock-in is never nice. So
for real-time string-heavy work, at the time of writing, reckless-utf8 is the only
usable alternative.
3Conformance
reckless-utf8 tries to conform to RFC-3629 as strictly as possible. Any violation isa bug and should be reported.4Usage Example
(let* ((s "café ᴑE")
(n (utf8-byte-length s))
(octets (make-array n :element-type '(unsigned-byte 8))))
(utf8-encode-into s octets)
;; octets now holds the strict UTF-8 bytes
(assert (utf8-valid-p octets))
(let ((out (make-string (length s))))
(utf8-decode-into octets out)
(assert (string= s out))))
4.1License
BSD 2-clause.