Daniel Lemire's blog
СтатистикаThis channel can be used to follow Daniel Lemire's blog. It is COVID-free. If you would like news on COVID, follow https://t.me/covidinfoenglish
- Последний пост
- 23:00
- Последнее чтение
- 12:08
- Постов за неделю
- 3
- Всего постов
- 21
- Тип
- открытый
- Язык
- английский
- Категория
- Новости и СМИ
- В каталоге с
- 13 авг.
- 1/24сутки в ленте
- 204
- 1/48двое суток
- 233
- 1/72трое суток
- 252
Оценка по просмотрам недавних постов: пост набирает почти всё за первые сутки.
Посты
Go 1.27 will make some allocations cheaper Like most programming languages, Go has both stack allocations, whose lifetime is limited to the current function, and dynamic (or heap) allocations. The name stack comes from the fact that the memory management is somewhat trivial. There is typically one stack per thread (or goroutine in Go). When a function needs memory, it simply appends data to the stack. When the function returns, the memory is dropped from the end of the stack. So the memory last allocated is deallocated first. Heap memory is potentially considerably more complex. For one thing, it is meant to be accessible by several threads (or goroutines). An object can be allocated by one function and later reclaimed after an entirely different function, possibly running on a different thread (or goroutine), has dropped the last reference to it. Unlike the stack, there is no… https://lemire.me/blog/2026/08/15/go-1-27-will-make-some-allocations-cheaper/
AI programming : are you angry yet? AI-assisted programming is fast evolving and there is a tension between ‘we no longer need to understand the code’ and ‘what is my purpose as a programmer’. I recorded a short video on this topic with how I think the tension can result in conflicts. https://lemire.me/blog/2026/08/12/ai-programming-are-you-angry-yet/
Profile-guided optimization in Go When a compiler optimizes your program, it has to guess. Which functions are worth inlining? Which side of a branch is the common one? Which method does this interface call actually reach? At compile time it cannot know, so it uses heuristics. Profile-guided optimization (PGO) replaces the guessing with measurement: you run your program, record where it spends its time, and hand that recording back to the compiler for a second build. PGO is a common feature of compiler systems. Google applied PGO to Chrome under Windows in 2016, reporting gains of up to 15%. I expect all mainstream Web browsers to be built with PGO. There are now fancier techniques than mere heuristics with PGO. You can use AI to recognize patterns and so forth. But they are not always widely available. Go has supported PGO since version 1.20. You collect a profile, and pass it to the compiler.… https://lemire.me/blog/2026/08/09/profile-guided-optimization-in-go/
How fast is C++26’s std::hive? C++26 adds a new container to the standard library: std::hive. It is meant to occupy the ground between std::vector and std::list. Like a vector, it keeps its elements in contiguous blocks of memory, so scanning it does not require you to chase a pointer for every element. Like a list, it never moves an element once it has been inserted: your pointers, references and iterators stay valid, and you may erase any element in constant time without disturbing the others. Internally, a hive is a linked list of blocks. Each block carries a skipfield: a small integer per slot that tells the iterator how many erased slots to jump over. No standard library ships std::hive yet to my knowledge. Fortunately there is an implementation (plf::hive by Matt Bentley) as a single header file that you can use today. I use elements of type uint64_t, GCC 16.1 with -O3{:space:}-march=native, on an Intel… https://lemire.me/blog/2026/08/02/how-fast-is-c26s-stdhive/
Memory-level parallelism: AMD is the king When your program asks for memory that is not in cache, the processor has to go to RAM. That trip costs on the order of 100 nanoseconds. On a 3 GHz core, that is about 300 cycles of doing nothing. Memory latency has not improved in ten years. The 2016 Broadwell answers a random access in 100 ns. The 2025 Turin, with DDR5-6400 and every advantage of a decade of progress, takes 140 ns. It got worse. The good news is that a modern core does not have to sit still. It can issue a second request before the first one comes back, and a third, and a tenth. The number of requests a single core can keep in flight is its memory-level parallelism. It is one of the most important numbers in software performance, and one of the least advertised: you will not find it on a spec sheet. Thankfully, memory-level parallelism has improved a lot. To measure it, I use my… https://lemire.me/blog/2026/07/25/memory-level-parallelism-amd-is-the-king/
Does a PhD Pay Off? Every week, I discuss with people who want to get a PhD. For years, I have been advising people not to pursue a PhD. It may come as a surprise to some. You would expect people with a PhD to earn more money. Individuals who complete doctorates tend to have higher cognitive abilities and greater motivation. But smarter people tend to earn more, period. So do people with a PhD earn more? Historically, PhD holders earn more, but the bulk of the observed advantage is concentrated among those who get a professorship after the PhD. And there is no certain path from the PhD to a professorship. We have been producing many more PhDs than we have professorship, for decades. And the disparity is ever growing. When I entered university at the beginning of the 1990s, about 0.5% of the Canadian population had a PhD. This has nearly tripled today, and it is fast increasing. Something of the order of one… https://lemire.me/blog/2026/07/24/does-a-phd-pay-off/
Using AI to build your own software A few years ago, a friend of mine was stuck. He needed to quickly process over a hundred high-quality images according to a complicated sequence. He was using Photoshop, but it was going to take him days. Initially, he asked for my help, could I do the manual labor? I spent 15 minutes writing a script with ImageMagick that processed all the images in seconds, but in a completely automated way. When my kids were young, instead of helping them study algebra and grammar, I wrote small JavaScript apps for them to use. I built a small collection of educational tools. The great success story of AI for me is exactly this: AI helps you write your own tools, faster and better. Last night, I was struggling with videos I had to process. I wanted to add nice subtitles to them. There are software applications for that, but they require manual labor and don’t always work the way I want them to. After a long night, I had an insight: why don’t I ask my AI to help build… https://lemire.me/blog/2026/07/16/using-ai-to-build-your-own-software/
X just gave us an interface that AI agents can use. I pointed it at my own posts. I have been on X for a long time. Like most people who post regularly, I have a gut feeling for what might interest people. I post in the morning. Longer posts seem to do better. But gut feelings are not measurements. And until recently, digging into your own posting data meant either clicking around the web UI or writing custom scripts. Neither is particularly friendly when you want to ask ad hoc questions with an AI assistant. X recently launched hosted MCP servers: official endpoints that AI tools can connect to. MCP is a protocol for plugging tools into language models: the model can search posts, manage bookmarks, fetch trends, and so on. In practice, I connected an AI coding agent to the X MCP server and simply started asking questions about my account. I spent a… https://lemire.me/blog/2026/07/11/x-just-gave-us-an-interface-that-ai-agents-can-use-i-pointed-it-at-my-own-posts/
Chatting with AI Won’t Make You a Top Programmer When I was a kid, most people did not know how to type. We took typing class. The final exam was a speed test: words per minute. Today, you will not impress anyone by saying you can type. In fact, cursive writing is fading. Kids increasingly cannot read or write it. We type constantly. We forget how many skills are learned, and how often some of these skills have faded. But not everything fades. Socrates would be immensely popular today as a teacher. I still buy and recommend paper books. Is reading and writing code more like Socrates, or more like cursive writing? There are clear signs that code could become like cursive writing. This year, I have met more than one student who could use AI to build an application but could not read or write code. It is not new. Software has long had non-technical people who describe what they built… https://lemire.me/blog/2026/06/21/chatting-with-ai-wont-make-you-a-top-programmer/
Parsing JSON at compile time with C++26 static reflection Suppose that you have a configuration file in JSON. Something like this: {"width":1920,"height":1080,"fullscreen":true,{:space:}"title":"My{:space:}Game","volume":0.8}{:space:} Normally you ship this file alongside your program, open it at startup, read it, and parse it. That is a lot of work for data that never changes. What if the file is fixed at build time? Could the compiler read it, parse it, and bake the result directly into the executable as a constant? With C++26, the answer is yes. We need two new ingredients, all of which are usable right now with the latest version of the GCC compiler (16). 1. #embed to pull the file into the program at compile time, 2. A software library supporting static reflection like simdjson. Let me show you how far we can take this. The new #embed directive reads a file and expands it into a… https://lemire.me/blog/2026/06/14/parsing-json-at-compile-time-with-c26-static-reflection/
Sovereign The keyword in politics these days is ‘sovereign’. What few will admit is that it is effectively the adoption of the American strategy: Make America Great Again. In other words, reindustrialization of key sectors of the economy. The UK used to be a computing champion. Our chip designs (ARM) originated from the UK. Canada had BlackBerry, everyone was using Canadian phones. Like Canada, many countries have progressively slid into financialization. Huge banks and bank-related businesses, surrounded by emptied factories. Part of it was the doing of economists who promoted globalization. We are going to make our best CPUs in Taiwan, because they have a comparative advantage (whatever that means). Another part is the rise of the managerial class, or our version of the technocracy: the summum of the status game is to make PowerPoint presentations in a nice office. Everyone has 2 or 3 university degrees. And if you don’t… https://lemire.me/blog/2026/06/09/22693/
How much do amd64 microarchitecture levels help in Go? Our 64-bit Intel and AMD processors have evolved over decades. When you compile a Go program for a 64-bit Intel or AMD processor, the compiler targets, by default, a nearly 20-year-old instruction set. The binary that comes out runs on essentially any x64 chip, but it also leaves on the table every instruction that was added since 2003. We often refer to microarchitecture levels. Each level bundles a set of instruction-set extensions that you can assume are present: Level | Adds (roughly) ------------------------------ v1 | the original AMD64 baseline (SSE2) ------------------------------ v2 | popcnt, SSE4.2 ------------------------------ v3 | AVX2 ------------------------------ v4 | AVX-512 (F/BW/DQ/VL) In my view, this ladder is already slightly obsolete. It was frozen around 2020, and the hardware has moved on. We… https://lemire.me/blog/2026/06/06/how-much-do-amd64-microarchitecture-levels-help-in-go/
Only 17% of all 64-bit Integers are products of two 32-bit integers In software programming, the product between two integers is often computed to a fixed number of bits with overflow. Consider 8-bit integers. If you multiply 127 by 127, you get back the number 1 as an 8-bit unsigned integer, with an overflow. The actual full product is 16129. To represent 16129, you typically use 16 bits of precision. Thus we have the notion of the full product. The full product of two 32-bit integers is typically represented using 64 bits. The question that preoccupied me is what fraction of all 64-bit integers can be written as the product of two 32-bit integers. You might wonder why you would care? We often design hash functions: they are special functions that take an input and generate a random-looking output. Several years ago I designed a very fast hash function called clhash… https://lemire.me/blog/2026/05/22/only-17-of-all-64-bit-integers-are-products-of-two-32-bit-integers/
SIMD-accelerated integer-to-string conversion Converting a 64-bit integer to its decimal string representation is a mundane task that shows up everywhere: logging, JSON serialization, CSV output, debug prints, etc. In C++, you might use std::to_chars, sprintf, or some library routine. How do these functions work? At a high level, they repeatedly divide by ten. Start with your integer k. Divide it by ten, use the remainder as the last digit (it is between 0 and 9 inclusively). You then add the code point value of the character 0 to get the ASCII digit. To go faster, you can divide by 100 and use a lookup table so that the value between 0 and 99 inclusively is mapped to a string. So far so good. Unfortunately, even with all these optimizations, this string generation may become a performance bottleneck. Can you do better? Let us assume that you have a recent AMD processor or an Intel… https://lemire.me/blog/2026/05/18/simd-accelerated-integer-to-string-conversion/
Checking multiplication overflow Suppose that x is a variable of an unsigned type. In C/C++, it could be of type size_t for example. You have an expression like 6 * x and you want to know whether 6 * x overflows. That is, you want to know if 6 * x exceeds the range of values that can be represented by the type. In most cases, a variable of type size_t will be about to represent all values in the range [0, 2^64-1]. Instead of 64, let me use a variable for the number of bits: [0, 2^L-1]. The easiest approach is to compare x with (2^L-1) // 6 where I use the symbol // to denote the integer division (as opposed to /). But can you do otherwise ? If the value does not overflow, we know for sure that (6 * x)//6 == x. The interesting question is what happens when it overflows. We… https://lemire.me/blog/2026/05/06/checking-multiplication-overflow/
Mapping Strings to Float Arrays in Go: How Fast Can We Go? A common pattern in modern software is to map a string key to a small array of floating-point numbers. Word embeddings, feature vectors, lookup tables for physical constants: all variations on the same theme. In Go, the obvious way to write this is a map[string][]float32. But how fast is it, really, and can we do better? I have been working on constmap, a Go library that builds an immutable map from strings to uint64 values using the binary fuse filter construction. A lookup amounts to one hash, three array reads, and two XORs. There is no comparison, no chaining, no probing. The whole table fits in roughly 9 bytes per key, which often means it fits in cache where a Go map does not. Go has fast maps, you cannot easily beat them in performance. But if you build a smaller data structure that causes fewer cache… https://lemire.me/blog/2026/05/05/mapping-strings-to-float-arrays-in-go-how-fast-can-we-go/
House prices and fertility No, rising house prices are not the driver of sharp fertility declines. The evidence shows only modest, mixed effects that cannot explain the large drops observed in places like Canada. What the Research Actually Shows: A well-known study by Dettling and Kearney (2014) found that rising house prices have opposing effects: they slightly increase fertility among homeowners (via a “home equity” or wealth effect) and slightly decrease it among renters (via a price effect). At average U.S. homeownership rates, the net effect was a small increase in fertility. This pattern has held up in other countries. For example, Daysal et al. (2021) and related work confirm similar homeowner/renter dynamics in Denmark and elsewhere. Clark (2012) found that expensive housing markets are associated with a modest delay in age at first birth (roughly 3–4 years after controls), but the overall… https://lemire.me/blog/2026/04/30/house-prices-and-fertility/
You can beat the binary search We sometimes have to look for a value in a sorted array. The simplest algorithm consists in just going through the values one by one, until we encounter the value, or exhaust the array. We sometimes call this algorithm a linear search. In C++, you can get the desired effect with the std::find function. For large arrays, you can do better with a binary search. Binary search is a classic algorithm that efficiently locates a target value in a sorted array by repeatedly dividing the search interval in half. Starting with the entire array, it compares the target to the middle element: if the target is smaller, it discards the upper half; if larger, it discards the lower half. This process continues until the target is found or the interval is empty. It is much faster than linear search for large datasets. In C++, this is implemented by the std::binary_search function,… https://lemire.me/blog/2026/04/27/you-can-beat-the-binary-search/
JSON and C++26 compile-time reflection: a talk The next C++ standard (C++26) is getting exciting new features. One of these features is compile-time reflection. It is ideally suited to serialize and deserialize data at high speed. To test it out, we extended our fast JSON library (simdjson) and we gave a talk at CppCon 2025. The video is out on YouTube. Our slides are also available. https://lemire.me/blog/2026/03/26/json-and-c26-compile-time-reflection-a-talk/
JSON and C++26 compile-time reflection: a talk The next C++ standard (C++26) is getting exciting new features. One of these features is compile-time reflection. It is ideally suited to serialize and deserialize data at high speed. To test it out, we extended our fast JSON library (simdjson) and we gave a talk at CppCon 2025. The video is out on YouTube. Our slides are also available. https://lemire.me/blog/2026/03/26/json-and-c26-compile-time-reflection-a-talk/