<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Tea and Bits</title><link>https://ohadravid.github.io/</link><description>Recent content on Tea and Bits</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 26 Feb 2026 16:00:00 +0000</lastBuildDate><atom:link href="https://ohadravid.github.io/index.xml" rel="self" type="application/rss+xml"/><item><title>Sliced by Go's Slices</title><link>https://ohadravid.github.io/posts/2026-02-go-sliced/</link><pubDate>Thu, 26 Feb 2026 16:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2026-02-go-sliced/</guid><description>&lt;style&gt;
.post .post-content {
 margin-top: 0px;
}
&lt;/style&gt;
&lt;p&gt;Today, I was sliced by Go&amp;rsquo;s slices. Actually, by Go&amp;rsquo;s variadics. Question: what does this snippet print?&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;func&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;main&lt;/span&gt;&lt;span style="color:#eceff4"&gt;()&lt;/span&gt; &lt;span style="color:#eceff4"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	nums &lt;span style="color:#81a1c1"&gt;:=&lt;/span&gt; &lt;span style="color:#eceff4"&gt;[]&lt;/span&gt;&lt;span style="color:#81a1c1"&gt;int&lt;/span&gt;&lt;span style="color:#eceff4"&gt;{&lt;/span&gt;&lt;span style="color:#b48ead"&gt;1&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; &lt;span style="color:#b48ead"&gt;2&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; &lt;span style="color:#b48ead"&gt;3&lt;/span&gt;&lt;span style="color:#eceff4"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#88c0d0"&gt;PrintSquares&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;nums&lt;span style="color:#81a1c1"&gt;...&lt;/span&gt;&lt;span style="color:#eceff4"&gt;)&lt;/span&gt; &lt;span style="color:#616e87;font-style:italic"&gt;// variadic expansion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	fmt&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;Printf&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;&amp;#34;2 %v\n&amp;#34;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; nums&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#eceff4"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;func&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;PrintSquares&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;nums &lt;span style="color:#81a1c1"&gt;...&lt;/span&gt;&lt;span style="color:#81a1c1"&gt;int&lt;/span&gt;&lt;span style="color:#eceff4"&gt;)&lt;/span&gt; &lt;span style="color:#eceff4"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#81a1c1;font-weight:bold"&gt;for&lt;/span&gt; i&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; n &lt;span style="color:#81a1c1"&gt;:=&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;range&lt;/span&gt; nums &lt;span style="color:#eceff4"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		nums&lt;span style="color:#eceff4"&gt;[&lt;/span&gt;i&lt;span style="color:#eceff4"&gt;]&lt;/span&gt; &lt;span style="color:#eceff4"&gt;=&lt;/span&gt; n &lt;span style="color:#81a1c1"&gt;*&lt;/span&gt; n
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#eceff4"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	fmt&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;Printf&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;&amp;#34;1 %v\n&amp;#34;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; nums&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#eceff4"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Answer (&lt;a href="https://go.dev/play/p/jy7gqxJUDNC"&gt;Playground&lt;/a&gt;):&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;1 [1 4 9]
2 [1 4 9]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;🫠&lt;/p&gt;
&lt;p&gt;Meaning, in Go, when you use a slice for variadic expansion (&lt;code&gt;s...&lt;/code&gt;),
and you use a variadic parameter to capture said slice (&lt;code&gt;paramSlice ...int&lt;/code&gt;),
they are the same&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt; slice, and mutating one will mutate the other.&lt;/p&gt;</description></item><item><title>&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;str</title><link>https://ohadravid.github.io/posts/2026-01-09-fourteen-ref/</link><pubDate>Fri, 09 Jan 2026 14:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2026-01-09-fourteen-ref/</guid><description>&lt;p&gt;While adding a failing test to the Rust compiler, I stumbled upon a peculiar &lt;a href="https://github.com/rust-lang/rust/blob/1.92.0/tests/codegen-llvm/issues/str-to-string-128690.rs"&gt;code generation test&lt;/a&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;pub&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;fn&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;thirteen_ref&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;input: &lt;span style="color:#81a1c1"&gt;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style="color:#81a1c1"&gt;str&lt;/span&gt;&lt;span style="color:#eceff4"&gt;)&lt;/span&gt; -&amp;gt; &lt;span style="color:#81a1c1"&gt;String&lt;/span&gt; &lt;span style="color:#eceff4"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#616e87;font-style:italic"&gt;// CHECK-NOT: {{(call|invoke)}}{{.*}}@{{.*}}core{{.*}}fmt{{.*}}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#616e87;font-style:italic"&gt;&lt;/span&gt; input&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;to_string&lt;span style="color:#eceff4"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#eceff4"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#616e87;font-style:italic"&gt;// This is a known performance cliff because of the macro-generated
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#616e87;font-style:italic"&gt;// specialized impl. If this test suddenly starts failing,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#616e87;font-style:italic"&gt;// consider removing the `to_string_str!` macro in `alloc/str/string.rs`.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#616e87;font-style:italic"&gt;//
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#616e87;font-style:italic"&gt;&lt;/span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;pub&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;fn&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;fourteen_ref&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;input: &lt;span style="color:#81a1c1"&gt;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style="color:#81a1c1"&gt;str&lt;/span&gt;&lt;span style="color:#eceff4"&gt;)&lt;/span&gt; -&amp;gt; &lt;span style="color:#81a1c1"&gt;String&lt;/span&gt; &lt;span style="color:#eceff4"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#616e87;font-style:italic"&gt;// CHECK: {{(call|invoke)}}{{.*}}@{{.*}}core{{.*}}fmt{{.*}}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#616e87;font-style:italic"&gt;&lt;/span&gt; input&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;to_string&lt;span style="color:#eceff4"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#eceff4"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In case you are wondering where are the tests here: the &lt;code&gt;CHECK&lt;/code&gt; and &lt;code&gt;CHECK-NOT&lt;/code&gt; comments are actually the test assertions, which are tested using &lt;a href="https://llvm.org/docs/CommandGuide/FileCheck.html"&gt;LLVM&amp;rsquo;s FileCheck framework&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Why is calling my asm function from Rust slower than calling it from C?</title><link>https://ohadravid.github.io/posts/2025-12-rav1d-faster-asm/</link><pubDate>Sat, 27 Dec 2025 10:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-12-rav1d-faster-asm/</guid><description>&lt;p&gt;This is a follow-up to &lt;a href="https://ohadravid.github.io/posts/2025-05-rav1d-faster/"&gt;making the rav1d video decoder 1% faster&lt;/a&gt;,
where we compared profiler snapshots of &lt;code&gt;rav1d&lt;/code&gt; (the Rust implementation) and &lt;code&gt;dav1d&lt;/code&gt; (the C baseline)
to find specific functions that were slower in the Rust implementation&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;Today, we are going to pay off a small debt from that post: since &lt;code&gt;dav1d&lt;/code&gt; and &lt;code&gt;rav1d&lt;/code&gt; share the same hand-written assembly functions,
we used them as &lt;strong&gt;anchors&lt;/strong&gt; to navigate the different implementations - &lt;em&gt;they&lt;/em&gt;, at least, should match exactly!
And they did. Well, &lt;em&gt;almost&lt;/em&gt; all of them did.&lt;/p&gt;</description></item><item><title>Making the rav1d Video Decoder 1% Faster</title><link>https://ohadravid.github.io/posts/2025-05-rav1d-faster/</link><pubDate>Thu, 22 May 2025 10:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-05-rav1d-faster/</guid><description>&lt;p&gt;&lt;em&gt;*on macOS with an M3 chip&lt;/em&gt; &lt;br&gt;
&lt;em&gt;*slightly more than 1%, on a specific benchmark, without any new unsafe code&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A while ago, &lt;a href="https://www.memorysafety.org/blog/rav1d-perf-bounty/"&gt;memorysafety.org announced a contest&lt;/a&gt; for improving performance of &lt;code&gt;rav1d&lt;/code&gt;, a Rust port of the &lt;code&gt;dav1d&lt;/code&gt; AV1 decoder.&lt;/p&gt;
&lt;p&gt;As this literally has my name written on it, I thought it would be fun to give it a try (even though I &lt;em&gt;probably&lt;/em&gt; can&amp;rsquo;t participate in the contest).&lt;/p&gt;
&lt;p&gt;This is a write-up about two small performance improvements I found (&lt;a href="https://github.com/memorysafety/rav1d/pull/1397"&gt;1st PR&lt;/a&gt;, &lt;a href="https://github.com/memorysafety/rav1d/pull/1400"&gt;2nd PR&lt;/a&gt;) and how I found them (you can also jump to the &lt;a href="#summary"&gt;summary in the end&lt;/a&gt;).&lt;/p&gt;</description></item><item><title>BTrees, Inverted Indices, and a Model for Full Text Search</title><link>https://ohadravid.github.io/posts/2025-04-08-btrees-and-mental-models/</link><pubDate>Thu, 10 Apr 2025 00:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-04-08-btrees-and-mental-models/</guid><description>Whenever I get into a new technology, I try to build myself a mental model of how it works. Let&amp;rsquo;s do that for &lt;em&gt;full text search engines&lt;/em&gt;, by writing a minimal implementation in Rust</description></item><item><title>Debugging a Vision Transformer Compilation Issue</title><link>https://ohadravid.github.io/posts/2025-01-debugging-vit-and-tensorrt/</link><pubDate>Wed, 22 Jan 2025 00:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-01-debugging-vit-and-tensorrt/</guid><description>After updating the TensorRT version we use to compile ML models at work, I got a failure in a test: the test feeds a video to a model expecting a specific classification, but the model produced complete garbage. This led me on an unusual debugging quest, dissecting a Vision Transformer layer by layer.</description></item><item><title>Making Python 100x faster with less than 100 lines of Rust</title><link>https://ohadravid.github.io/posts/2023-03-rusty-python/</link><pubDate>Tue, 28 Mar 2023 00:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2023-03-rusty-python/</guid><description>&lt;p&gt;&lt;em&gt;Update: I gave a talk on this topic at &lt;a href="https://youtu.be/Jb_kdYEXVw8?si=buwUwuDzz5oRn3KA"&gt;P99 CONF 2023&lt;/a&gt; and at &lt;a href="https://youtu.be/Tc9MlJN2y04?si=iE_Af883R6ublqbR"&gt;PyCon IL 2024 (Hebrew)&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A while ago at &lt;a href="https://www.trigoretail.com/"&gt;$work&lt;/a&gt;, we had a performance issue with one of our core Python libraries.&lt;/p&gt;
&lt;p&gt;This particular library forms the backbone of our 3D processing pipeline. It’s a rather big and complex library which uses NumPy and other scientific Python packages to do a wide range of mathematical and geometrical operations.&lt;/p&gt;
&lt;p&gt;Our system also has to work on-prem with limited CPU resources, and while at first it performed well,
as the number of concurrent physical users grew we started running into problems and our system struggled to keep up with the load.&lt;/p&gt;</description></item><item><title>A Rust API Inspired by Python, Powered by Serde</title><link>https://ohadravid.github.io/posts/2025-05-serde-reflect/</link><pubDate>Wed, 07 May 2025 12:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-05-serde-reflect/</guid><description>Years ago, I worked on reimplementing some Python code in Rust and needed to adapt Python’s dynamic reflection capabilities (aka &lt;code&gt;__getattr__&lt;/code&gt;) to the strict and compiled world of Rust&amp;hellip;</description></item><item><title>Frankenstein’s `__init__`</title><link>https://ohadravid.github.io/posts/2025-04-19-frank/</link><pubDate>Sat, 19 Apr 2025 10:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-04-19-frank/</guid><description>The untold story of the craziest &lt;code&gt;__init__&lt;/code&gt; I’ve ever seen.</description></item><item><title>Put a Pin on That</title><link>https://ohadravid.github.io/posts/2023-07-put-a-pin-on-that/</link><pubDate>Tue, 11 Jul 2023 17:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2023-07-put-a-pin-on-that/</guid><description>&lt;p&gt;There are some things you keep learning and forgetting (or perhaps you&amp;rsquo;ve never learned them in the first place?).&lt;/p&gt;
&lt;p&gt;For me, one of those things is &lt;code&gt;Pin/Unpin&lt;/code&gt; in Rust.&lt;/p&gt;
&lt;p&gt;Every time I &lt;a href="https://fasterthanli.me/articles/pin-and-suffering"&gt;read&lt;/a&gt; an &lt;a href="https://blog.cloudflare.com/pin-and-unpin-in-rust/"&gt;explanation&lt;/a&gt; about &lt;a href="https://doc.rust-lang.org/std/pin/index.html"&gt;pinning&lt;/a&gt;, my brain is like 👍, and a few weeks later is like 🤔🤨.&lt;/p&gt;
&lt;p&gt;So, I&amp;rsquo;m writing this as a way to force my brain to retain (pin?) this knowledge. We&amp;rsquo;ll see how it goes!&lt;/p&gt;
&lt;h1 id="pin"&gt;Pin&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;Pin&lt;/code&gt; is &lt;em&gt;a type of pointer&lt;/em&gt;, which can be thought of as a middle ground between &lt;code&gt;&amp;amp;mut T&lt;/code&gt; and &lt;code&gt;&amp;amp;T&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>State of the Crates 2025</title><link>https://ohadravid.github.io/posts/2024-12-state-of-the-crates/</link><pubDate>Mon, 09 Dec 2024 00:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2024-12-state-of-the-crates/</guid><description>&lt;p&gt;One of the best things about Rust is that there are so many high-quality crates for everything and anything you want.&lt;/p&gt;
&lt;p&gt;It can be hard to choose, so I wanted to share some of the crates I used this year at $work and explain why.&lt;/p&gt;
&lt;p&gt;You can also jump to the end for the &lt;a href="#tldr"&gt;final &lt;code&gt;Cargo.toml&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For context, we&amp;rsquo;re a small-ish Rust &amp;amp; Python shop handling compute-heavy workloads on-prem. Our system is split into a reasonable number of services that talk to each other mostly over RabbitMQ or HTTP.&lt;/p&gt;</description></item><item><title>My most downvoted StackOverflow answer</title><link>https://ohadravid.github.io/posts/2024-09-yells-at-cloud/</link><pubDate>Thu, 05 Sep 2024 00:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2024-09-yells-at-cloud/</guid><description>&lt;p&gt;Sometimes, I get mad at someone on the internet.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://ohadravid.github.io/2024-09-yells-at-cloud/old_man_yells_at_cloud.png" alt="Old Man Yells at Cloud meme"&gt;&lt;/p&gt;
&lt;p&gt;It’s just so easy, isn’t it?&lt;/p&gt;
&lt;p&gt;Then, I remember my most downvoted StackOverflow answer, and I become less angry.&lt;/p&gt;
&lt;p&gt;I wrote the actual answer many years ago, but the angry-ness is much more recent.&lt;/p&gt;
&lt;p&gt;Apparently, I angered someone on a topic that is &lt;em&gt;so&lt;/em&gt; controversial that my answer became part of a &lt;a href="https://meta.stackoverflow.com/"&gt;StackOverflow Meta&lt;/a&gt;(!) &lt;a href="https://meta.stackoverflow.com/questions/420337/what-is-the-procedure-for-getting-blatantly-off-topic-c-or-c-answers-deleted"&gt;discussion&lt;/a&gt; about how to deal with such terrible answers.&lt;/p&gt;</description></item><item><title>Winning the fight against the Rust compiler (Coherence in Rust, feat. rustc sources)</title><link>https://ohadravid.github.io/posts/2023-05-coherence-and-errors/</link><pubDate>Wed, 10 May 2023 12:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2023-05-coherence-and-errors/</guid><description>&lt;h2 id="an-unexpected-error"&gt;An unexpected error&lt;/h2&gt;
&lt;p&gt;A friend was experimenting with Rust and asked if I could help decipher an error message for them:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-ps" data-lang="ps"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;PS&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;Z:\Projects\aoc\src\bin&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;cargo&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;build&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;--bin=2021_day19&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#88c0d0"&gt;Compiling&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;aoc&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;v0.1.0&lt;/span&gt; &lt;span style="color:#a3be8c"&gt;(Z:&lt;/span&gt;&lt;span style="color:#ebcb8b"&gt;\&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;Projects&lt;/span&gt;&lt;span style="color:#ebcb8b"&gt;\&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;aoc)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;error&lt;/span&gt;&lt;span style="color:#eceff4"&gt;[&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;E0210&lt;/span&gt;&lt;span style="color:#eceff4"&gt;]&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;:&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;parameter&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;`T`&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;must&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;be&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;covered&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;by&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;another&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;when&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;it&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;appears&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;before&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;the&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;first&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;local&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt; &lt;span style="color:#a3be8c"&gt;(`VecN&amp;lt;T, N&amp;gt;`)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#88c0d0"&gt;--&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;src\vec.rs:65:6&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#88c0d0"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#b48ead"&gt;65&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;|&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;impl&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;T:&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;MulAssign,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;const&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;N:&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;usize&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;Mul&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;VecN&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;T,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;N&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;for&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;T&lt;/span&gt; &lt;span style="color:#eceff4"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#88c0d0"&gt;|&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;^&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;parameter&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;`T`&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;must&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;be&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;covered&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;by&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;another&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;when&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;it&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;appears&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;before&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;the&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;first&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;local&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt; &lt;span style="color:#a3be8c"&gt;(`VecN&amp;lt;T, N&amp;gt;`)&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#88c0d0"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#88c0d0"&gt;=&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;note:&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;implementing&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;a&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;foreign&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;trait&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;is&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;only&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;possible&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;if&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;at&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;least&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;one&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;of&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;the&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;types&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;for&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;which&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;it&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;is&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;implemented&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;is&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;local,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;and&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;no&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;uncovered&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;parameters&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;appear&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;before&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;that&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;first&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;local&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;type&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#88c0d0"&gt;=&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;note:&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;in&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;this&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;case,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;&amp;#39;before&amp;#39;&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;refers&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;to&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;the&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;following&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;order:&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;`impl&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;..&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;ForeignTrait&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;T1,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;...,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;Tn&lt;/span&gt;&lt;span style="color:#eceff4"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;for&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;T0`,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;where&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;`T0`&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;is&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;the&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;first&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;and&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;`Tn`&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;is&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;the&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;last&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And, I could! I actually updated this error message (in &lt;a href="https://github.com/rust-lang/rust/pull/66253"&gt;#66253&lt;/a&gt;) after helping stabilize &lt;a href="https://github.com/rust-lang/rust/issues/63599"&gt;RFC 2451 (re-rebalance coherence)&lt;/a&gt; in &lt;a href="https://github.com/rust-lang/rust/pull/65879"&gt;#65879&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But this error is indeed strange.&lt;/p&gt;
&lt;p&gt;Isn’t one of the reasons for using traits is to allow others to implement them?
Why does Rust reject this particular combination of structs, traits and generics?&lt;/p&gt;</description></item><item><title>How to Build Python Code with Bazel (and Why)</title><link>https://ohadravid.github.io/posts/2025-09-hello-bazel/</link><pubDate>Tue, 09 Sep 2025 06:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-09-hello-bazel/</guid><description>&lt;style&gt;
.post .post-content {
 margin-top: 0px;
}

.post hr {
 margin: 0px;
}
&lt;/style&gt;
&lt;p&gt;How can you build Python code with &lt;a href="https://bazel.build/"&gt;Bazel&lt;/a&gt;? Why would you even want to do that?&lt;/p&gt;
&lt;p&gt;This is the topic of a lightning talk I gave at PyCon IL this year.
Below are the slides and a transcript, starting with &lt;em&gt;why&lt;/em&gt; this is a problem that you might have.
You can also jump right into &lt;a href="#how-bazel-solves-these-problems"&gt;the part about how Bazel can solve that problem&lt;/a&gt;,
or &lt;a href="https://github.com/ohadravid/hello-bazel-pycon-il"&gt;check the GitHub repo&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Zig is not F'ing memory safe</title><link>https://ohadravid.github.io/posts/2025-05-zig-mem-safety/</link><pubDate>Sat, 10 May 2025 08:00:00 +0000</pubDate><guid>https://ohadravid.github.io/posts/2025-05-zig-mem-safety/</guid><description>&lt;style&gt;
.post .post-content {
 margin-top: 0px;
}
&lt;/style&gt;
&lt;p&gt;It&amp;rsquo;s not. I&amp;rsquo;m not saying that&amp;rsquo;s &lt;em&gt;inherently bad&lt;/em&gt;.
It&amp;rsquo;s just what it is.
Consider the following code:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-zig" data-lang="zig"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;var&lt;/span&gt; gpa &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; std&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;heap&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;GeneralPurposeAllocator&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(.{}){};&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;const&lt;/span&gt; allocator &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; gpa&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;allocator&lt;/span&gt;&lt;span style="color:#eceff4"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;var&lt;/span&gt; list &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;try&lt;/span&gt; std&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;ArrayList&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#81a1c1"&gt;u8&lt;/span&gt;&lt;span style="color:#eceff4"&gt;).&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;initCapacity&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;allocator&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; &lt;span style="color:#b48ead"&gt;4&lt;/span&gt;&lt;span style="color:#eceff4"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;try&lt;/span&gt; list&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;appendSlice&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;&amp;#34;Hell&amp;#34;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;const&lt;/span&gt; c &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#81a1c1"&gt;&amp;amp;&lt;/span&gt;list&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;items&lt;span style="color:#eceff4"&gt;[&lt;/span&gt;&lt;span style="color:#b48ead"&gt;0&lt;/span&gt;&lt;span style="color:#eceff4"&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;try&lt;/span&gt; list&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;append&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;&amp;#39;o&amp;#39;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;try&lt;/span&gt; list&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#88c0d0"&gt;append&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;c&lt;span style="color:#eceff4"&gt;.&lt;/span&gt;&lt;span style="color:#81a1c1"&gt;*&lt;/span&gt;&lt;span style="color:#eceff4"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It compiles just fine but triggers a segfault due to a Use-After-Free bug in the last line:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ zig run main.zig
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Segmentation fault at address 0x104b00000
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;aborting due to recursive panic
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;zsh: abort zig run main.zig
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you have a &lt;a href="https://matklad.github.io/2023/03/26/zig-and-rust.html#TigerBeetle"&gt;use case&lt;/a&gt; where you don&amp;rsquo;t care about that -
you do you!&lt;/p&gt;</description></item><item><title/><link>https://ohadravid.github.io/index-about/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://ohadravid.github.io/index-about/</guid><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;This is my blog. I write about software, performance, Rust, Python and the like.
Usual disclaimer: views are my own.&lt;/p&gt;
&lt;p&gt;Everything here is written entirely by me: LLMs are cool and all, but writing is &lt;a href="https://x.com/michael_cryne/status/2019302988825637300"&gt;like going to the gym&lt;/a&gt;, and sharing an LLM&amp;rsquo;s writing on the internet without disclosure is &lt;a href="https://rfd.shared.oxide.computer/rfd/0576"&gt;rude&lt;/a&gt;.&lt;/p&gt;</description></item></channel></rss>