Jan 19, 2025
Neat GitHub Commits —
A notable amount of code I’ve written in my professional life has made
its way onto GitHub. Here’s a collection of some of my commits that I
think are neat. (Disclaimer: I wrote these while employed at Meta,
where I am still employed at the time of writing. However, this is my
personal space and my employer does not necessarily endorse the things
I stay in my personal spaces. In particular, I am merely pointing to
and summarizing public information below.)
Jan 18, 2025
From the Vault: Unionizing for Profit —
Back in 2021, I wrote about unions in my professional capacity (disclaimer: this is my personal space and my employer does not necessarily endorse what I say here) on the PyTorch Dev Discussions forum. Stick with (or skip) the C++ 101 “What is a union?” section and you’ll be rewarded with the advanced material in the second half. Please enjoy!
Apr 3, 2021
The Sad Truth About C++ Copy Elision —
Copy elision is a C++
compiler optimization that, as its name suggests, eliminates extra
copy and move operations. It is similar to the classical copy
propagation
optimization, but specifically performed on C++ objects that may have
non-trivial copy and move constructors. In this post, I’ll walk
through an example where an obvious optimization you might expect from
your compiler doesn’t actually happen in practice.
Mar 14, 2021
How to Read ARM64 Assembly Language —
ARM64 is a computer
architecture
that competes with the popular Intel
x86-64 architecture used for
the CPUs in desktops, laptops, and so on. ARM64 is common in mobile
phones, as well as
Graviton-based Amazon
EC2 instances, the Raspberry Pi 3 and 4, and the much
ballyhooed
Apple M1 chips, so knowing
about it might be useful! In fact, I have almost certainly spent
more time with ARM64 than x86-64 because of the iPhone.
Mar 7, 2021
Parameter Passing in C and C++ —
Now that we know how to read assembly
language,
we can talk about how parameter passing works at the machine level and
its consequences for writing faster code. We will focus on x86_64, but
ARM64 works in a roughly similar way.
Feb 26, 2021
How to Read Assembly Language —
UPDATE: This article now has an ARM64
port.
Why, in 2021, does anyone need to learn about assembly language?
First, reading assembly language is the way to know exactly what
your program is doing. Why, exactly, is that C++ program 1 MiB (say)
instead of 100 KiB? Is it possible to squeeze some more performance
out of that function that gets called all the time?
Jan 23, 2021
Inlining and Compiler Optimizations —
Why is inlining so
important in C++? Clearly, it reduces function call overhead:
if a function is inlined, there is no need to spend time setting up
its arguments, jumping to it, creating a stack frame, and then undoing
all that upon returning. More interestingly, though, inlining enables
other compiler optimizations. In this article, I will show examples of
constant
propagation
and loop-invariant code
motion
(LICM). Then, I will explain how inlining enables these optimizations
to apply more widely and show an example of the consequences when that
doesn’t happen.
Jan 14, 2021
C++ Performance Trap #2: Unnecessary std::function —
std::function
does what it says on the tin: it holds any callable object. For example, you can use lambdas with or without captures. It has a couple key drawbacks:
Jan 14, 2021
C++ Performance Trap #1: Constant-size std::vector —
The C++ standard library has many classes and functions that are easy
to use and relatively safe. However, in situations where performance
and efficiency really matter, straightforward use of the standard
library may not always be the best choice. This post is the first in a
series that will catalogue some of those opportunities for
improvement. It is meant to be accessible to people who are not C++
gurus or language lawyers.
Jan 14, 2021
How This Site Is Made —
TLDR: Hugo, GitHub, Netlify.
Putting writing on a website in 2021 is surprisingly pleasant, despite a few glitches.
I wanted to have a plain old static site. I can write raw HTML well
enough, and I knew about Bootstrap,
but that still seemed like too much work. Instead, I looked at a
couple
overviews of static site generators, and
I ended up picking Hugo as the one most fitting
my sensibilities. You write pages and posts in Markdown, run Hugo, and
get static HTML/CSS/JS out. It has a built-in web server with hot
reloading so that you can run hugo server
, edit your site, and see
it in your browser right away. The builds are really fast; I am using
a potato cheap Chromebook from
2018
and the site still builds in less than 100 ms.