Building Static Wget

May 20th, 2024

I recently came across a need for wget, but I did not want to have to keep a bunch of dependencies installed. Wget is not hard to build, but there are a couple of dependencies needed during the build. It’s possible to build them all statically, so the resulting wget executable has no runtime dependencies on having those other libraries installed. You’ll need the source for:

  • libgmp (tested with 6.3.0)
  • libnettle (tested with 3.9.1)
  • libtasn1 (tested with 4.19.0)
  • gnutls (tested with 3.7.10)
  • wget (tested with 1.24.5)

Read the rest of this entry »

Sky Simulation

May 13th, 2024

For my game, I would like to have a realistic sky in the background. I have a preference for a procedurally-generated sky over a skybox. But then, I need to learn about different ways of modeling the sky.

I first considered reusing the computations in the sky example from Three.js’s documentation, as it is liberally licensed. However, I decided I’d like to understand more of the theory behind it and use my own implementation instead of copying the Three.js’s example’s code.

The Three.js example’s implementation references the Preetham model. Introduced in 1999, the Preetham model seems to have been the baseline standard for a procedural sky for a long time. The original paper does its best to explain the scientific terminology to graphics practitioners, but there is still enough left unsaid that I found the paper hard to interpret in isolation. The most useful reference I found providing necessary background knowledge is Timothy Kol’s technical report. Kol also implements and compares the newer 2012 Hošek–Wilkie model. The remainder of this post mostly distills information from these three papers.

Read the rest of this entry »

Getting the Perf out of perf script

May 6th, 2024

I’m a big fan of sampling profilers. I tend to prefer them over tracing profilers, due to the more limited amount of distortion they create in the measurements.

To start off with, Go has its own sampling profiling tool through runtime/pprof. These emit a pprof file which can be fed into pprof. pprof can generate various reports and visualizations. You can also use the same tool for heap and allocation profiling. This tool is molded in the shape of gperftools, another Google release, which works similarly but for native code. For gperftools, you link in the profiler with -lprofiler, and then set the CPUPROFILE environment variable and you’re on your way. You can use the very same pprof you’d use with Go, or you can use its predecessor, a Perl script also named pprof.

Both of these are great, but there’s a limitation: They rely mostly on counters, so while you can see where most of the time is spent, you can’t easily see when that time had been spent. This is where you’d want something more like a Flamegraph.

Read the rest of this entry »

Drawing Rounded Rectangles

April 29th, 2024

While working on my little game, I’ve iterated through different ways of displaying game state:

  1. Command line
  2. Web page
  3. 2D canvas
  4. 3D canvas

In each port, I preserve some elements and change others out. One of the elements I want to keep from the 2D version in the 3D version is rounded rectangles.

Initially, I used NanoVG to render the 2D elements into 3D. This works, but NanoVG is a lot of code. It’s very general. I don’t need that level of generality. I just want rounded rectangles. So how do we do that?

Read the rest of this entry »

What is Plausible Doing For You?

April 22nd, 2024

Plausible is a privacy-focused analytics service. It is available hosted by them, or can be run on your own. What does it do for you? We’ll explore a bit of the journey from a user visiting a web page, to that page view appearing in the analytics dashboard. Read the rest of this entry »

SQL INSERT to COPY FROM Conversion

April 15th, 2024

While reproducing an example from ClickHouse’s blog, I needed to insert some data provided as SQL with INSERT statements.

INSERT is the standard transactional way to insert data into a database. There’s nothing wrong with it. But when you’re trying to insert data into a PostgreSQL database in bulk, there’s a better way: COPY FROM.

When using COPY, PostgreSQL itself will read and parse a file full of row data and insert it into a table. There is very little overhead of parsing SQL, etc. This is the format used by pg_dump by default when producing an SQL dump output. But, to use it, the input data must be in the right format. PostgreSQL explains the format it expects in its documentation. It’s basically TSV with a couple of provisions for escaping values.

On the other hand, the input we’ve got is an SQL file looking like this: Read the rest of this entry »

Reproducing ClickHouse Postgres Integration Example

April 8th, 2024

I was recently reading this article from ClickHouse demonstrating ClickHouse’s integration with Postgres and performance characteristics. I followed along. Here are my notes.

My experimental setup was slightly different. Rather than using hosted services (Supabase and ClickHouse Cloud), I ran everything locally on my M2 MacBook Air. Versions in question:

  • PostgreSQL 15.6 (Postgres.app) on aarch64-apple-darwin21.6.0, compiled by Apple clang version 14.0.0 (clang-1400.0.29.102), 64-bit
  • ClickHouse server version 23.12.4.15 (official build).

Read the rest of this entry »