Manually Building a Nix Derivation: A Deep Dive into Hash Generation

2025-04-09
Manually Building a Nix Derivation: A Deep Dive into Hash Generation

This blog post details the author's journey in manually building a simple Nix derivation. By dissecting Farid's blog post step-by-step, the author delves into the inner workings of Nix derivations, specifically the hash generation process. The journey involved overcoming challenges such as understanding ATerm representation, SHA256 hashing, and Nix's unique base32 encoding. Ultimately, the author successfully generated the same hash value as in Farid's blog post and successfully built a simple "hello world" derivation.

Read more
Development Hash Generation

100x Speedup: Garbage Collection and GPUs in Python

2025-03-25
100x Speedup: Garbage Collection and GPUs in Python

This post details how the author achieved a 100x speedup of a Python program through simple code optimizations. The initial program used NumPy for parallel computation but was slow and memory-intensive due to poor memory management. By implementing a simple garbage collection mechanism to release unused intermediate variables, the author reduced runtime from 40 seconds to 10 seconds, significantly decreasing memory usage. Subsequently, using CuPy to offload computation to the GPU further reduced runtime to 1.5 seconds, demonstrating a dramatic performance improvement.

Read more
Development Python Optimization

Cinder JIT: Efficient Type Representation Using Bitsets and Semilattices

2025-03-11
Cinder JIT:  Efficient Type Representation Using Bitsets and Semilattices

The Cinder JIT compiler employs a clever type representation, treating types as sets (even lattices) and choosing a compact bitset representation. This article delves into how Cinder leverages bitsets and semilattice structures for efficient type information handling, covering basic type representation, type unions, and specialization. By encoding type information into bitsets, Cinder effectively represents type unions and allows for finer-grained type distinctions. Furthermore, Cinder introduces a specialization mechanism to track the specific value of individual objects, further improving compiler optimization efficiency. The article also discusses the Bottom type and details on generating the type lattice.

Read more
Development bitsets

A Deep Dive into Static Single Assignment (SSA) Compiler Optimizations

2025-02-11
A Deep Dive into Static Single Assignment (SSA) Compiler Optimizations

This article chronicles the decades-long evolution of Static Single Assignment (SSA) compiler optimization techniques. From the early papers on code motion and global value numbering, through Cytron's seminal work on minimizing phi instructions, to Brandis and Mössenböck's single-pass generation approach, and Click and Paleczny's Sea of Nodes IR, the article traces several key papers and discusses their strengths and weaknesses. It also touches upon Appel's work on the relationship between functional programming and SSA, Aycock and Horspool's iterative phi node removal, and more recent approaches based on abstract interpretation. The article concludes with a list of further papers and resources, providing a more comprehensive perspective for readers interested in learning more about SSA.

Read more

Deep Dive into CPS: A Journey into Functional Programming Compilation

2024-12-25
Deep Dive into CPS: A Journey into Functional Programming Compilation

This article delves into Continuation-Passing Style (CPS) and its application in compiling functional programming languages. The author builds a CPS transformer step-by-step for a simple Scheme-like language, explaining optimization strategies and code generation methods. The article details the transformation of integers, variables, function calls, arithmetic operators, lambda expressions, and if expressions into CPS form. It also discusses meta-continuations and optimization techniques such as constant folding and beta reduction. Finally, it outlines several approaches to generating executable code from CPS, including generating C code, using trampolines, and employing a single large switch statement.

Read more