Welcome to my blog
Removing a Type Assertion with Object.assign
I loathe type assertions in TypeScript. Every as is a spot where I am telling the compiler ātrust meā, and every as unknown as is me telling it to stop thinking altogether. So when I found one in an adapter function I was working on, I wanted to get rid of it. In the process, I learned an interesting fact about how unknown and Object.assign behave together. The Adapter The setup was roughly this: a library exposes a function that takes a client, and that client must have a request function resolving to a Response with a typed json method. On my side, I already had a function that does the request and returns the parsed data directly. I just needed to adapt one to the other. ...
Lottery Scheduler
An operating system virtualizes the CPU so that it becomes easier for it to be used. Even when there is a single CPU, the OS can make it appear as if multiple processes are running at the same time, concurrently. To make that work, an OS needs to schedule which process will run and for how long. The scheduler may optimize for different metrics, but one idea is that of a proportional-share scheduler, which tries to make each process have a certain percentage of CPU time. Interestingly enough, one example of a fair-share scheduler is the CFS (Completely Fair Scheduler) from Linux. It is a pretty complex scheduler with more than 10K lines (see GitHub mirror). ...
Context Switch Time
Iām learning about CPU virtualization and the Limited Direct Execution model. Part of CPU virtualization is allowing multiple processes to share a CPU and run concurrently. A context switch occurs when the operating system pauses one process and resumes another, requiring the CPU to save and restore process state. This overhead can significantly impact system performance, so measuring it helps us understand the cost of multitasking. After the syscall time homework, I also got a task to measure how much a context switch costs1. The book mentions that LMbench uses the following approach to measure it: ...
How Long Does a System Call Take?
Iām learning about CPU virtualization and the Limited Direct Execution model. As part of that, I got some homework1 to measure how long a system call takes. The book suggests: Measuring the cost of a system call is relatively easy. For example, you could repeatedly call a simple system call (e.g., performing a 0-byte read), and time how long it takes; dividing the time by the number of iterations gives you an estimate of the cost of a system call. ...
Performance Issues with Large Data in window.history.state
TL;DR: Storing full collection data in window.history.state is expensive (serialization time, retained memory, and browser size limits). Prefer storing cursors/params and keep large data in an in-memory cache keyed by URL; use sessionStorage/IndexedDB if persistence is required. Iāve found an interesting issue with the Shopify Hydrogen component because it saves all nodes on a page in window.history.state as you can see in this line. For the particular website I am working with at the moment, the collection page has quite a bunch of data. When I tested, showing about 100 products on the page meant having ~8MB for the serialized version of the object using JSON.stringify. Deserialized structures also incur engine overhead (object headers, indices). The Pagination component from Shopify that we use does many things, but what I want to emphasize is that it saves the collection data in window.history.state: ...
File Descriptors and stdout redirection
I took a few computer science electives during my Mechatronics Engineering major, but unfortunately I didnāt attend operating system lectures, although I had all the pre-requisites. Iāve decided to study the subject and Iāve found a free book which is quite good. On Chapter 5 about the Process API, there are details about how the Unix Process API works, detailing some system calls. Iāve found the trick for file redirection particularly interesting: ...
Resizing FreeBSD QEMU Images: Fixing 'Truncated ELF File' Errors
Iāve been curious about FreeBSD and wanted to try it on QEMU. FreeBSD has instructions for running it. As Iām using an Apple Silicon machine, I paid attention to the HVF acceleration option. I first logged in via Telnet, but once SSH was set up, I ran it in the background with a small script (./run.sh &): #!/bin/sh qemu-system-aarch64 -m 4096M -cpu host -M virt,accel=hvf \ -bios edk2-aarch64-code.fd -display none \ -drive if=virtio,file=FreeBSD-14.3-RELEASE-arm64-aarch64-ufs.qcow2,id=hd0 \ -device virtio-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 This worked well, but as I installed more packages I eventually hit a weird error: ...
My Bun Migration Story: From CI to Local Development
My Experience with Bun Iāve been using Bun for a while now. The first time Iāve heard about it I thought it was cool that it uses JavaScriptCore instead of V8 and that I could use it as a drop-in replacement for npm install. As a web developer working on Shopify Hydrogen apps, I ended up just staying with the project defaults, which meant npm. Moving CI to Bun However, as we added more steps to our CI, like additional lint rules, I noticed the pipeline slowed down significantly. In particular, I observed that our dependent steps spent substantial time on the installation phase. Due to that, a year or so ago I decided to experiment with Bun on our CI for all our steps, including deployment. ...
HTML - Semantic Meaning and the Anchor Element
When I reviewed HTML for my current job, I was concerned about using elements that not only contain style but also meaning, semantics. This is something I saw frequently while studying iOS on my free time and and only later I found out the web also had it, but I never paid attention to it as I was too busy thinking about layout, styles and data. However, using elements with semantics help us convey our intent better and the browser can also help us with common implementations for the element we used. ...
Solid Parakeet
I have been working with VueJS for a while, but I also have some ReactJS experience. I was curious to see how the framework and ecosystem advanced in the couple years I hadnāt touched it so I decided to read some docs. I got excited and also created Anki cards for it to sediment my knowledge, but thatās a topic for another post (let me know if you are interested in knowing more how I do it). In this post, I intend to show you the main points I learned of each item, mixing it with some thoughts from previous experiences, and what the demo app (Solid Parakeet) does (which is not much really). ...