6 ms·
Building a web server in aarch64 assembly to give my life (a lack of) meaning
- thisislife2 6mo agoThis is an interesting project - kudos for executing it. I have to admit that when I was starting out in this field, I too fantasised about, "Would this software be faster, smaller and better in assembly?". Ofcourse, assembly programming made some sense in embedded electronics, which can be very resource constrained and even specialised for one particular application. Thinking from that aspect, perhaps you should consider making this a specialised program that runs on something like a Raspberry Pi - running such a web server directly on it, without an OS (or a very minimal OS), would make for a real cool and interesting project.
- senfiaj 6mo agoIMHO, for servers IO (FS/DB, network, etc) is usually a greater bottleneck. Microoptimizations make sense only for CPU bound problems.
- jvanderbot 6mo agoI am pained to think of TLS/HTTPS implemented as a hobby project in ASM, but would be impressed to see it.
- LegionMammal978 6mo agoI did actually make an attempt at that once for BGGP5 [0]. (That is, making a minimal, horribly insecure 'client' implementing just enough behavior to get a response from a server.) But I got demoralized by how much space the binary blobs for the crypto algorithms took up, in comparison to the actual machine code. [0] https://binary.golf/5/ https://binary.golf/5/
- dorianmariecom 6mo agothat url leads to scam
- cevn 6mo agoIf you keep scrolling down there is some kind of contest, I was confused at first as well. It seems to be parodying scam sites.
- grebc 6mo agohttps://2ton.com.au/rwasa/ https://2ton.com.au/rwasa/
- tyingq 6mo agoYou could borrow the output of the perl scripts from openssl. https://github.com/openssl/openssl/blob/master/crypto/aes/asm/aes-armv4.pl https://github.com/openssl/openssl/blob/master/crypto/aes/as...
- golem14 6mo agoI'd really like to see a TCP/IP stack written in native forth (if anyone needs a really good therapist, that sounds like a _great_ project to try ;) I mean, it doesn't look _that_ daunting, but the fact that noone seems to ever have release an open source version (there are rumours of proprietary stacks though) speaks for itself. One of these days ...
- HeliumHydride 6mo agoThis is a web server, but not a full TCP/IP implementation: https://news.ycombinator.com/item?id=19146767 https://news.ycombinator.com/item?id=19146767
- golem14 6mo agoYes, well aware of it, that's actually very nice for building higher levels of the webserver. I'd really like to have a complete forth machine dealing with everything, say on an esp32. I guess there's FreeRTOS, so I could use that network layer, but bare metal would be so much cooler. I admit I don't even understand how it would work - would I have to bit-bang the ethernet lines?
- seba_dos1 6mo agoYou interface with SoC's peripherals rather than bit-bang lines. You can think of them as a kind of memory mapped APIs.
- golem14 6mo agoI never interface with the peripheral in an ESP32 directly. I guess I really need to read the Free-RTOS code. Micropython just uses that, last I checked.
- thisislife2 6mo agoI was thinking more of the memory usage. As another project posted on HN described, they were running the web server in the RAM of an RPi ( https://news.ycombinator.com/item?id=48064312 https://news.ycombinator.com/item?id=48064312 ). Without a full-fledged OS, and a tiny (and fast) webserver coded in Assembly, more RAM would be available for the webserver and they could serve more users.
- hatefulheart 6mo agoWhat on earth are you talking about? Assembly makes sense in desktop computing as well. Have you ever, for example, watched a video? What do you think powers the codecs, JSX?
- xnorswap 6mo agoI'd assume most are written in C or some other higher level language. Certainly I checked the x264 ( VLC implementation of h264 ) and that is C.
- otherjason 6mo agoThe statistics reported by GitLab for the x264 repo (https://code.videolan.org/videolan/x264 https://code.videolan.org/videolan/x264) report that the project is 13.5% assembly; common utilities used in the inner loops of the codec have optimized assembly implementations for several CPU architectures.
- xnorswap 6mo agoI stand corrected.
- jamal-kumar 6mo agoA lot of the encoding side on ffmpeg now uses hand-coded assembly optimizations to take advantage of avx512 instructions on newer x64 processors for "100x speed increase" since February 2025 in a stable form https://www.techspot.com/news/108715-ffmpeg-gets-100x-faster-avx-512-handwritten-assembly.html https://www.techspot.com/news/108715-ffmpeg-gets-100x-faster...
- thisislife2 6mo agoYes, I do know that some Assembly is used in systems programming and other niches where it makes sense. To be clear, I was talking about the phase some of us go through (as amateurs) when we think everything would be "faster, smaller, better" if written in assembly - Python is slow. What about C or Pascal? Wouldn't asm be faster? ... but, as we all realise sooner or later, there's a reason we prefer to code in high-level or very high-level languages, and why pre-mature optimisation can be a real handicap.
- pixelesque 6mo agoPrevious comments from two days ago: https://news.ycombinator.com/item?id=48080587 https://news.ycombinator.com/item?id=48080587
- theanonymousone 6mo agoSomething funny has happened. I didn't submit this link today, as is shown in the front page. I submitted three days ago, before the original author (above submission) actually.
- tomku 6mo agoHN has a "second chance queue" that sometimes revives posts and gives them another shot. Not entirely sure how it works, but it sounds like what happened here.
- globnomulous 6mo agoMaybe combine the threads, dang?
- peterpanhead 6mo agoFun project.
- DeathArrow 6mo agoMeanwhile another 10000 developers published desktop apps, mobile apps and system software written in javascript. /s
- _f9cu 6mo agoHow to do assembly only to build a web server for the hardware? I mean it may sound like building os from scratch.
- StilesCrisis 6mo ago"i hate string parsing. especially in assembly." Well. Interesting choice of side project!
- globnomulous 6mo agoI love this. I'm wondering: what skills did this project hone? What are you better at now than you were before you undertook it? Or was it just for fun?
- Serhii-Set 6mo ago[dead]
- drob518 6mo agoI’m curious what the performance of this implementation is versus a server written in C, C++, or Rust. How much performance can a human still squeeze out at the assembly level versus today’s state of the art compilers?
- pjdesno 6mo ago> I’m curious what the performance of this implementation is Almost certainly crap. As the author states, it's a simple fork-on-request server, which was state-of-the-art in about 1996. But that's not the point.
- jubilanti 6mo agoAnd that wasn't the question the parent comment asked.
- tredre3 6mo agoThe parent asked two questions: 1. What is the performance of this implementation of an assembly server? The comment you replied to answered it: It's likely crap. Hand written assembly is almost always worse than compiler. 2. How much performance can a human still squeeze out at the assembly level? That question is different and remains unanswered. But in my experience the answer is the same.
- mananaysiempre 6mo ago> How much performance can a human still squeeze out at the assembly level versus today’s state of the art compilers? Most of the squeezing is to be had in the parts where the compiler can’t help. (Which I guess is logically equivalent to saying that you can’t often do meaningfully better than the compiler on the things that the compiler is concerned with, but you have to admit it reads very differently.) Two important widely-applicable examples are data layout (locality, in particular getting rid of large and costly-to-traverse pointers) and vectorization; what they have in common is that you may well have to redesign the entire flow of data in your program around the issue before you get meaningful improvements. (And there is often an order-of-magnitude improvement to be had on a CPU-bound task, if you are willing to spend the time and effort to optimize.) There are also specific situations where the approaches used by modern compilers work badly. The straightforward switch-based interpreter is a well-known example: modern Clang essentially turns into Clippy and goes “looks like you’re writing an interpreter, would you like me to duplicate your dispatch for you” so branch prediction works out as well as in manual assembly, but it still allocates registers a function at a time, so when the function in question is the entirety of the interpreter including the slowpaths, the regalloc sucks. Tail-call interpreters and __attribute__((cold, noinline, preserve_most)) amount to expressing the exact same control-flow graph in such a way that the compiler can digest it better, ironically by understanding less of it at any given time. This is one way that the dumb fundamental nature of the admittedly quite smart modern compiler shines through. And in very tight loops there are still places when doing things by hand can help. For instance, when computing a histogram of byte values over a large block (for which I’m not aware of any public vectorized code that would go faster than the best scalar options) I’ve seen Clang lose as much as 20% to (contemporary) GCC on the best C implementation[1] or its straightforward manual translation to assembly, because Clang had decided it knew better which order the instructions should go in. As a less exotic case, I’ve seen GCC lose out by about 20% to (contemporary) Clang in vectorized loops because it had decided that having half the loop body be MOVs (or rather VMOVDQAs) would be a better idea than taking advantage of AVX’s ability to not overwrite either of the input arguments, and though MOVs are basically free on a superscalar they’re not that free. I’ve even seen both GCC and Clang ignore an explicit __builtin_expect() and compile a very predictable (but unavoidable) inner-loop branch into a CMOV, once again costing me about 20% in performance. So if you do in fact care about the difference between 1.1 cycles/byte and 1.3 cycles/byte, yes you can beat a compiler even on a micro level. You just probably don’t have the, depending on your point of view, fortune or misfortune of working on code like that. [1] https://github.com/powturbo/Turbo-Histogram https://github.com/powturbo/Turbo-Histogram
- nikisweeting 6mo agoNice, I've been trying to learn assembly myself recently and built a little REPL to play around with it directly https://github.com/pirate/assembly-repl https://github.com/pirate/assembly-repl But I've struggled with the IO parts, it seems every system is so different, it's hard to live without LLVM-IR as the middle layer abstracting away compiler and target differences.
- declank 6mo agoThere is the lesser-known web server rwasa written in flat assembler: https://2ton.com.au/rwasa/ https://2ton.com.au/rwasa/
- triilman 6mo agoI have created the same project but for Risc-V https://github.com/triilman25/tcp-socket-in-riscv-assembly https://github.com/triilman25/tcp-socket-in-riscv-assembly
- podlp 6mo agoThe work of a true masochist, but in all seriousness, it’s a solid article explaining aarch64 assembly in plain language.