Most recent posts
- Bootstrapping a Forth for Art
- My dad was an economist, and the only computer he knew how to operate was his trusty old HP-12C, a financial calculator that uses Reverse Polish Notation (RPN). He eventually taught me how to use it, and that was the first time I was exposed to a… Published August, 30
- Toying with a toy Garbage Collector
- When learning a new programming language, I either write something I've written multiple times, or dive-in head first into some random project for a drive-by contribution. Historically, I've written web servers, as that usually exercises things I care… Published June, 10
- Macro to lazily initialize globals
- C lacks the concept of constructors, making it hard to define global variables that are semi-constants in a foolproof way. Here's a trick I'm now using in Lwan, that might be useful for those wanting semi-constants that are initialized exactly once, or… Published February, 23
- Macro to loop over executable sections
- Defining things in different sections in a binary is really useful – and used by quite a few projects, from operating system kernels to web servers, like Lwan. Lwan makes extensive use of this: Published January, 08
- Dancing with light
- Many years ago, I helped a friend with her capstone project. She wanted to design the clothes used by dancers, in a performance similar to the The Wrecking Crew Orchestra, a Japanese group that performs in pitch-black theaters, with eletro-luminescent… Published September, 27
- Blurhash-like without JS
- Here's a fun trick: implementing a Blurhash-like thing for galleries, without requiring JS, just plain CSS. Published September, 18
- How async/await works in Lwan
- Some people over the years told me they were interested in knowing how asynchronous I/O works in Lwan. I've already written a bit how asynchronous I/O works with HTTP clients, but this was a long time ago and a refresher might be useful, as new features… Published February, 29
- Locale-neutral case-insensitve string equality comparison
- After reading Daniel Stenberg's post on case-insensitive string comparison in cURL, I decided to take a stab at implementing something like this in Lwan for the same reasons. (Lwan used to use strcasecmp() before using the one described in this blog post.) Published September, 15
- Using MAP_FIXED_NOREPLACE for JITs
- It's been a while since I've blogged about the JSON library optimization work I did for Lwan's entry in the TechEmpower Web Framework Benchmarks. I've been taking a break from a lot of my personal projects, so the work to generate machine code from the… Published May, 23
- Huffman decoder for HPACK
- Out of the many benefits of HTTP/2 is its ability to not waste bandwidth with headers when compared to HTTP/1.1. This is achieved by doing three things: Published March, 27
- Implementing TLS in Lwan
- One of the long standing tasks in Lwan is to implement HTTP/2. I've been postponing it since before it was fully standardized, and followed a lot of public discussions that turned SPDY into HTTP/2. I had a few false starts, but never really started the… Published March, 23
- Implementing a playlist shuffler
- A few weekends ago, I decided to break my hiatus of recreational programming and play a bit with Serenity OS. What I decided to play with was the SoundPlayer application, to avoid working on the kind of stuff that I'm usually drawn to – and learn a few… Published October, 06
- Encoding tables in constants
- A common pattern you see in programs are predicates such as is_action_allowed(), or should_perform_action(), taking a constant value, often from an enumerated type, and returning a boolean value. A straightforward way to implement such predicates is to… Published April, 06
- Choosing your first programming language
- A while back I opened an online form so that people could ask me anonymous questions, and posted it on Twitter. Then I forgot about it – until today, when I was cleaning up my online docs, and saw quite a few questions there, waiting to be answered. Oops! Published March, 06
- ★ Converting GW-BASIC to the Z80
- Right after the BUILD conference, Microsoft released the source code for the first version of GW-BASIC for the MS-DOS under the MIT license. Not only this is an improved version of the very first product that kickstarted the company, it's also the base… Published June, 21
- Optimizing a JSON serializer (part 1)
- A few years back, I wrote a tiny JSON library for the Zephyr OS; it focused mostly in things that are important for an embedded real-time operating system: code size, type-safety, and predictability (both for memory and CPU time usage). It was never tuned… Published February, 10
- Lwan: 5 years in snippets
- Around five years ago, I wrote a blog post that went though the life-cycle of a HTTP request, as seen by my toy web server, Lwan. It was a surprisingly popular article, not only raising visibility for my toy project, but also generating some discussions… Published October, 24
- include_next and portability
- One of the decisions I took early on while writing Lwan was to only support Linux, and think about portability later; this decision was influenced by the way the OpenBSD project approaches portability. Published June, 28
- ★ More on string switch in C
- Talking about uncommon programming tricks the other day, the subject of switching on strings in C appeared on the table. Published February, 01
- Coreboot & LUKS
- My laptop is a 6-year old ThinkPad X220. Although it's almost falling apart from years of constant abuse, I don't see myself replacing it anytime soon: it's easy to repair, has a great keyboard, and is a very dependable machine. Published May, 08
- Parsing JSON
- There are many libraries out there to parse JSON files. It might be a futile attempt, then, to write yet another one. However, when you're working on a RTOS where memory is golden, and the alternatives don't look that great, you got to do something about… Published March, 01
- Infect to Protect
- I’m not one to jump on each and every bandwagon I see. Sometimes that’s a good decision, sometimes it’s better to just wait and see where they go before taking any action. Published November, 08
- Hybrid C/Pascal Strings
- I've been thinking for a while on how to reduce the overhead in Lwan's string buffer, when the strings are small. There are a number of ways of accomplishing this. Published November, 02
- ★ Life of a HTTP request, as seen by my toy web server
- When learning a new programming language, I tend to write two things with it: a language interpreter (usually a FORTH-like language or Brainfuck if I'm feeling lazy), and a HTTP server. Sometimes, just as a challenge or a way to quench my boredom, I do… Published October, 06
- Integer to string conversion
- There are various ways to convert integers to their string representation. These conversions are rarely a bottleneck, but they often show up while profiling certain applications. For instance, they're very common in Lwan while building the response… Published June, 23
- Reducing Lwan memory usage by 94%
- One of the things that bothers me when I'm writing software is that I never get things right the first time. It takes me quite a few iterations to achieve a good result -- be it performance, memory usage, or a good architecture. Getting things to a "good… Published December, 08
- Implementing sequences in lwan template engine
- When I wrote about lwan's templating engine on a blog post last year, I purposedly ommitted the fact that it didn't support sequences. Took me almost a year, but I've finally implemented it this week. (Lwan is usually a low priority weekend project. Maybe… Published September, 26
- ★ Partially Applied Functions in C
- There are some functions in the standard C library that takes a function pointer to be used as a callback later on. Examples include atexit() and signal(). However, these functions can't receive an arbitrary pointer (which could hold some important… Published July, 20
- Mustache templates in C
- Generating textual output is a lot easier with templates than it is with handcrafted functions. And it is a lot easier in languages such as Python, where things like introspection are easy and cheap. But that doesn’t necessarily mean we can’t do that in C… Published November, 11
- Programming on an Arduino without a PC
- I’ve attended this year’s FISL, both as a booth attendee (at ProFUSION’s booth, demonstrating a few of our end-user-visible projects), and as a speaker for my old FINF project. Published October, 27
- Vectored I/O with mmap() to serve files
- Previously, I’ve improved file serving performance in lwan by dramatially cutting down on the number of system calls performed to serve a file. However, for small files (< 16KiB), the throughput drop from the hello handler (which merely responds “Hello,… Published October, 14
- Asynchronous I/O in C with Coroutines
- Writing asynchronous I/O code in C is kind of tedious, and often leads to a callback hell. But it doesn’t have to be this way; if you have a main loop, it’s quite simple to use coroutines and write code in a soothing, old school, synchronous way. Published September, 29
- Presenting EasyUI
- I’ve been working at ProFUSION on a project called EasyUI for the past few months. This library is based on Google’s V8 JavaScript engine and the Enlightenment Foundation Libraries and aims to diminish the hurdle in writing native applications for the… Published September, 21
- File serving with few system calls
- When I first wrote lwan, file serving was not a primary goal. I’ve added this capability later, never giving much thought to the number of system calls required to serve one file. As a result, static file serving was quite slow compared to “hello world”… Published August, 12
- Deferred statements in C
- Golang has a lot of nice features – and one I found pretty interesting is called deferred statements. This can be implemented in C++ pretty easily through RAII, but in C we’re pretty much out of luck. Or are we? Published August, 11
- Hash trie
- Tries are very useful data structures if you need to perform longest subprefix matching. Unfortunately, simple implementations uses a lot of memory, which is often solved by collapsing common prefixes in a single node (like a Radix tree). However, this… Published August, 10
- String switch in C
- C’s switch statement is very powerful. However, it can’t be used with strings, only with constant integral types. This is understandable, since strings in C are merely arrays – they’re not first-class citizens. Published August, 09
RSS feed · Powered by the Lwan web server · Copyright © 2025 L. A. F. Pereira