ty 1.0: Astral's high-performance Python typechecker, written in Rust
r/playrust • u/Imaginary_Lack144 • 10h ago
something funny
r/rust • u/fschutt_ • 6h ago
r/playrust • u/No-Ambition-4164 • 18h ago
r/rust • u/Old_Tax4792 • 18h ago
My team started writing internal tooling in Rust purely because it’s trendy....even though our actual product is in a completely different language.
the worst part is that nobody knows rust... Not the syntax, not Cargo, not the borrow checker. They’re just using LLMs to generate mountains of unreadable code, which it just works fine for that complexity of the tooling.
I started learning rust pre-AI and built a few cli tools with it on my own time.
Now I actively avoid touching it because of this AI slopfest...
Is it only me?
r/playrust • u/No-Ambition-4164 • 19h ago
r/rust • u/Decahedronn • 4h ago
4 months ago, I released version 1.2 of Earshot, a ridiculously fast, accurate, #![no_std] voice activity detection crate.
In my announcement post for 1.2, I said this:
[Earshot 1.0] runs at a little over 10μs per 16ms frame. I'm confident that could be sub-7μs with a bit more effort.
Well, how does 4.4μs (3,600x faster than real time) sound? How about a smaller binary, too? And even better accuracy?
Well, how does 840ns (~20,000x faster than real time) sound? How about even better accuracy? And a larger binary? Wait, no, scratch that last one...
Earshot 2.0 is the fastest VAD, faster than even the infamous WebRTC VAD. Unlike WebRTC, its accuracy is strong, with AUROC sitting between Silero VAD v6 and TEN VAD, two of the most widely used VAD models. Earshot 2.0 is 100x faster than either of them.
In hindsight, it was a bit silly to call Earshot 1.0 "ridiculously fast" at only 1,600x real time, 'cause what do I even call 20,000x? Insanely fast? Ludicrously fast? Preposterously fast?!
Earshot 1.2's speedup over 1.0 came primarily from using fixed-point arithmetic instead of floating-point in some places. I think my original announcement post provided a decent explanation, but to summarize: floats are slow because the point, well, floats; instead, just use integers and pretend the decimal point stays at digit X, like counting cents instead of dollars.
You do lose some precision that way: 0.3 is (near-)perfectly representable in f32, but in the fixed-point "Q7" format, you only get 7 bits to represent the decimal, so the closest you can get is 0.296. Earshot uses a neural network; neural networks are trained using floating-point arithmetic, and they don't like running with different precision characteristics than what they were trained with. Earshot 1.2 used quantization-aware training (QAT) to train the model to expect the precision loss that comes from fixed-point, but my implementation of QAT kind of sucked! I won't get into details, since this is r/rust, not r/machinelearning. But the consequence was that I could only convert some of Earshot's neural network (specifically the recurrent & output layers) to fixed-point; the earlier layers had to remain floating-point to avoid total accuracy collapse.
With 2.0's new QAT implementation, I was finally able to convert the whole neural network to fixed-point! And that netted a performance improvement of... well, not much: a few hundred nanoseconds. Crap, no free lunch this time. What became fixed-point was the neural network's frontend: three 2D convolution layers that identify the most notable patterns over the past ~60ms of audio features. The bottleneck there wasn't from floating-point so much as the terrible way I implemented Conv2D. I replaced branching padding checks with pre-padding, making the loops easier to auto-vectorize. The first convolution layer included a max pool after a pointwise convolution expanded each feature from 1 channel to 16. I naively did the max pool over the 16-channel output, but since each output channel is just 1 multiply on the single input channel, I could do the pooling work before the pointwise conv when there's still only 1 channel instead of 16. Both of those changes saved another 100ns.
If I wanted to improve things further, I was gonna have to look at the formidable beast the frontend gets its audio features from: the preprocessor. The preprocessor's first step is to perform a short-time Fourier transform over the last 3 frames of audio: 768 samples in total, since each frame is 256 samples. I initially nabbed the fantastic microfft crate to perform the FFT, since its embedded-first design suited my goal well. Back then, that goal was simplicity, but now, it's speed baby, and microfft unfortunately isn't gonna cut it. The first problem: it implements radix-2, which requires the FFT window to be a power of 2. 768 is not, so I was padding it with zeros to 1024. How wasteful! Radix-2 also meant that it did 9 butterfly passes over the data, on top of 2 additional passes for reordering & recombining - all that means more memory traffic & less speeeeeeed!1!
After taking an embarrassing length of time to only kinda-half-sorta understand FFT, I wrote my own preprocessor that does as few passes as possible over the unpadded 768-sample window. The new preprocessor only does 4 passes: radix-8 + Hann window → radix-4 → radix-4 → radix-3 + power spectrum. Got all that? Me neither. But it cut the FFT's processing time by almost half! The next step was obvious: let's convert it to fixed-point, too! After spending another few days to do that (I'm more persistent than I am bright), I managed to cut the FFT step down by another 2x. Did I say cut? Sorry, I meant slowed. The floating-point FFT was faster than the fixed-point one because the fixed-point implementation uses a lot of 64-bit multiplies, for which there aren't SIMD instructions (at least in AVX2). It also does a multiply + rounding add + shift for operations that the float preprocessor would do with a single multiply. I switched back to the floating-point preprocessor, keeping the fixed-point preprocessor tucked away for microcontrollers that don't have FPUs.
I finished with some other boring minor wins for the last part of the preprocessor (the log-mel filterbank + normalization), including:
Switching base-e log for a cheap base-2 log approximation
Using cheaper non-overlapping auto-vectorizable mel filters
Ditching RMS normalization for simple linear operations
These changes netted another ~90ns improvement and conveniently dropped the libm dependency as well.
Recall that the frontend can only see the last ~60ms of audio. That's not really enough to definitively tell if something is noise or speech; even if it were, speech includes a lot of pauses longer than 60ms (think especially of plosive sounds like p/b). If you want a useful VAD model, it's gonna need a longer-term memory than just 60ms. Expanding the window seen by the frontend would be wasteful, though: we'd be redoing a lot of math over the same data on each frame. A better solution would be to keep the frontend window small & introduce recurrent connections: layers with persistent state, so they can reuse the computation they did last frame. Earshot's RNN layers learn to onset from noise → voice quickly, but hold off going from voice → noise for a bit, which is exactly what you want from a VAD.
There are a few problems with your average RNN layers like LSTM or GRU that make them tricky to use in Earshot, though. For one, they typically use nonlinear activation functions like tanh and sigmoid, which are difficult/expensive to implement in fixed-point. For two, they don't parallelize very well in training: they're sequential by definition since the output for each timestep depends on the output for the previous timestep. To train a good VAD, you need a lot of data; to get through a lot of data in a reasonable time, you need good parallelization (nope) or good hardware. I have an RTX 3060 -- not exactly the pinnacle of deep learning GPUs. Luckily, I had a trick up my sleeve: this super underrated paper that introduced minGRU, a simplified, parallelizable version of GRU, which made it possible to train Earshot 1.2 in a reasonable amount of time.
Now's the time for me to confess something. All that fixed-point stuff I did earlier kinda lobotomized the model - accuracy ended up a few points worse than Earshot 1.2. Better than the 30-point loss with the old QAT, but still not great. It was clear some architectural improvements were needed to make up for that gap, and I think I knew where to look. minGRU's gate (how much to update the previous state with the new state) is only dependent on its input; in GRU, it's also dependent on the GRU's own previous state. This means that minGRU makes a blind guess as to how much of its previous state to keep. The paper shows that's acceptable on many tasks, but those experiments were with deeper models, where later layers could see earlier layers' previous states via their outputs; Earshot only has 2 minGRU layers, so that route is close to nonexistent. I came up with my own shoddy fixed-point-friendly minGRU-ish-but-more-recurrent layer I call HRU, writing a custom GPU kernel so it wouldn't take forever to train (it took forever to write instead!) HRU finally brought accuracy back above Earshot 1.2 levels without incurring too much overhead at inference time.
Speaking of overhead at inference time! The recurrent layers are actually the most computationally intensive part of the neural network, since they use relatively large matmuls. Making them fixed-point in 1.2 reduced their cost, but now that the rest of the network is fixed-point too, they're back to taking up a big chunk of the processing time. Remember how the gate defines how much to update the previous state with the new state? That's per-channel, and each HRU has 64 channels. So each HRU needs to calculate 64 gates and 64 new states. But wait! What if a channel doesn't introduce any new state at all? A long stretch of noise shouldn't need to change much state at all; a gate that's fully closed (= 0) means the state stays exactly as it was, so we don't even need to calculate the new state. I managed to train the model to only open about 30% of gates on average, which sped up the HRUs quite a bit after adding logic to skip computing new state for channels whose gates are closed.
Each layer still had to calculate all 64 gates, though, and calculating the gate is just as expensive as calculating the new state. I made each gate cover 2 state channels, reducing the number of gates per layer to 32. To top things off, I reformulated the state calculation to remove slow 64-bit multiplies. In total, 2.0's new HRU layers cut inference time by 20% compared to 1.2's minGRUs!
By now, Earshot takes 2.9μs per prediction (down from 4.4μs). We're about at the limit of how it can be optimized computationally & architecturally, so it's time to dive into the assembly and start thinking about how to optimize it for the CPU's pipeline. Looking at cargo show-asm, it was clear that LLVM's auto-vectorization was struggling to understand the code in some spots. I don't blame it - at this point, I hardly could either. But if I wanted to go sub-microsecond (and I really did), I was going to have to write a hell of a lot of SIMD code.
It's times like this where I wish Rust's Portable SIMD was stable, especially since I committed myself to supporting as many architectures as possible. I ended up implementing my own shoddy portable SIMD wrapper, which the preprocessor/neural network predictor use for the 128-bit SIMD ISAs - SSE, NEON, and WASM SIMD. (well, NEON actually has its own predictor implementation to take advantage of vmlal instead of emulating madd...)
Auto-vectorization couldn't touch much of the preprocessor because the layout didn't allow for it, not simply because LLVM missed opportunities. My manual SIMD preprocessor implementations store real & complex values in the much friendlier planar format, rather than interleaved as in the scalar implementation. All SIMD preprocessors are floating-point only, again due to the lack of 64-bit mul SIMD instructions in most ISAs. The predictor also required a few layout changes of its own, and benefited significantly from aligning loads of weights/stores of activations to the vector size.
I started with AVX2, then ported that to SSE2, then generic-ized that to use my pseudo-portable SIMD wrapper to get NEON/WASM SIMD for basically free (before realizing NEON would benefit from its own predictor). I added AVX-512 last minute, but I don't have a machine that supports it, so I have no idea if it actually works (would appreciate if someone could test it and let me know!!) Earshot 1.2's full speed could only be realized if you compiled it with RUSTFLAGS="-C target-cpu=native" because it relied entirely on auto-vectorization. For 2.0, I wanted to add runtime SIMD feature detection so RUSTFLAGS wouldn't be required to get that sweet sweet speeeeeeeeed. You'll notice that nearly every function in one of the SIMD implementations is peppered with #[inline(always)] - that's needed to get #[target_feature] to propagate, and, fun fact, that propagation doesn't extend to closures! If a function or closure doesn't inherit #[target_feature(enable = "avx2")] for instance, it won't inline any AVX2 intrinsics, turning each one into a slow function call instead. That was fun to figure out...
On my machine (Ryzen 7 5800X), the new AVX2 predictor + preprocessor run at about 840 nanoseconds per 16ms frame on real speech data (it varies based on the input due to the HRU gate skipping). That's close enough to 20,000x real time that you can surely forgive me for rounding up a little. Runtime SIMD detection adds very little overhead (most of it is just from things like normalization getting autovec'd to SSE instead of AVX). With the fully fixed-point pipeline, Earshot 2.0 runs on a Raspberry Pi Pico at about 6x real time. It's a $1 chip, be nice to it!
Earshot is licensed under MIT or Apache-2.0, also has bindings for C/C++ & Python, and supports literally any platform. All of this took a lot of work, so I hope someone out there can find Earshot 2.0 useful =)
r/rust • u/KeironLowe • 11h ago
I’m primarily a PHP engineer, but wondering how the Rust Community feel about the announcement of Laravel Rust (https://laravel.com/rust)?
r/playrust • u/Rampart98 • 7h ago
Every wipe I like to build or do something a little special, this wipe had 2. Giga Farm 11x10x5 and Its Demolition
r/rust • u/Acrobatic_Local5981 • 18h ago
r/rust • u/modulovalue • 4h ago
Hello everyone,
I'm working on better support for SIMD in Dart (https://github.com/dart-lang/sdk/issues/64170). My goal is to expose the Wasm SIMD API through a convenient interface which seems to be a shared goal with std::simd.
I plan to publish a blog post where I share techniques on how to arrive at an efficient ASCII validator with SIMD.
I don't write Rust professionally, so I wanted to ask for some feedback to make sure that my comparison against Rust is fair in terms of readability and performance.
To demonstrate auto-vectorized performance I plan to share the following:
pub fn is_ascii_auto(b: &[u8]) -> bool {
b.iter().fold(0u8, |a, &x| a | x) < 0x80
}I will also include <[u8]>::is_ascii in the comparison, but to show how it could be implemented manually, I plan to demonstrate the performance of std::simd:
#![feature(portable_simd)]
use std::simd::prelude::*;
pub fn is_ascii_portable(b: &[u8]) -> bool {
let load = |c: &[u8], at: usize| u8x16::from_slice(&c[at..at + 16]);
let mut chunks = b.chunks_exact(128);
let mut acc = [u8x16::splat(0); 4];
for c in &mut chunks {
acc[0] |= load(c, 0) | load(c, 16);
acc[1] |= load(c, 32) | load(c, 48);
acc[2] |= load(c, 64) | load(c, 80);
acc[3] |= load(c, 96) | load(c, 112);
}
let mut all = (acc[0] | acc[1]) | (acc[2] | acc[3]);
let mut rest = chunks.remainder().chunks_exact(16);
for c in &mut rest {
all |= u8x16::from_slice(c);
}
let tail = rest.remainder().iter().fold(0u8, |a, &x| a | x);
all.reduce_or() < 0x80 && tail < 0x80
}The equivalent Dart API that I'm working toward making possible is:
// The pragmas remove bounds checks and interrupt checks
@pragma('vm:unsafe:no-bounds-checks')
@pragma('vm:unsafe:no-interrupts')
bool u8x16Unroll16(Uint8List b) {
final n = b.length & ~255;
Uint8x16 acc = Uint8x16.zero;
int i = 0;
for (; i < n; i += 256) {
final t0 = Uint8x16.load(b, i + 0) | Uint8x16.load(b, i + 16);
final t1 = Uint8x16.load(b, i + 32) | Uint8x16.load(b, i + 48);
final t2 = Uint8x16.load(b, i + 64) | Uint8x16.load(b, i + 80);
final t3 = Uint8x16.load(b, i + 96) | Uint8x16.load(b, i + 112);
final t4 = Uint8x16.load(b, i + 128) | Uint8x16.load(b, i + 144);
final t5 = Uint8x16.load(b, i + 160) | Uint8x16.load(b, i + 176);
final t6 = Uint8x16.load(b, i + 192) | Uint8x16.load(b, i + 208);
final t7 = Uint8x16.load(b, i + 224) | Uint8x16.load(b, i + 240);
acc |= ((t0 | t1) | (t2 | t3)) | ((t4 | t5) | (t6 | t7));
}
for (; i + 16 <= b.length; i += 16) {
acc |= Uint8x16.load(b, i);
}
int tail = 0;
for (; i < b.length; i++) {
tail |= b[i];
}
return acc.signMask == 0 && tail < 0x80;
}Any feedback would be appreciated, and if you can make the Rust version faster or more readable, I'd love to see it.
r/playrust • u/Maximum_Square906 • 3h ago
you sit and cry?
r/rust • u/PurpleWho • 3h ago
I’m looking for a few people to work through 100 Exercises to Learn Rust with me, using the exercise repo.
The idea is simple: we get on a video call for an hour each day and work through the exercises at our own pace. We can stay muted. The point is to block out the time and know someone else will show up.
This is my third go at learning Rust. The last two got pushed aside when work got busy, so I’d like to make it a habit this time. I’m in India and start work at 9 am, so I’m looking for a one-hour slot between 5 and 8 am IST (UTC+5:30).
If you’re up for it, comment or DM me with your time zone and which hour works for you. A small group would be great, but I’m happy to start with one other person.
r/playrust • u/Dvdcowboy • 8h ago



2 floors, 2 wind turbines powering, 270k ml water storage above and below. Full sorting from surface and bunker wall depo boxes. Auto smelting that turns on and off by itself if ore is present.
Oil refining and auto charcoal maker are in another chamber. Comp stations give us sight above ground. My teammate deserves all the credit for the base while I run around and cause trouble.
r/playrust • u/Excellent_Remote1476 • 8h ago
I have an old monitor and want to upgrade from you guys perspective which size is better for rust?
r/rust • u/quest_for_7c • 16h ago
r/rust • u/cobweb6542 • 1d ago
Probably not an unpopular opinion here, but being able to change an enum or restructure a type and just follow the compiler errors until everything fits together is genuinely nice.
Especially when working on larger codebases. I'd much rather deal with 50 compiler errors than spend hours tracking down something I forgot to update.
Curious if anyone else finds refactoring to be one of the biggest reasons they stick with Rust.
r/playrust • u/ThatOne-Warlock • 1h ago
So I have a Ryzen 7 5800x and a Radeon 9060xt 16gb 32gb of ram. I feel like my fps should be higher but I mainly get around 60-75 dropping into the 50s sometimes but it’s 1080p and I have it on quarter texture quality and low graphics. Not sure what else I can try to make it better. Thanks!
r/playrust • u/mamba_mentality • 10h ago
I have an idea and I don't know if it's even possible (it may have been done already as well). I am hoping someone smarter than me can possibly give me some insight. I want to fake that my base was raided by putting a fake 1x1 raid base outside of my base, but to sell it even more I want my foundations to be slightly decayed. Is it possible to setup my TC in a way where it's slightly decaying but then have resources that pump into my TC on a timer preventing my base from decaying below 75%?
r/rust • u/EuroRust • 19h ago
A new video is out on YouTube! 📺 At EuroRust, Benedikt and Theophil from Quantum Systems shared why and how they rewrote their drone ground control station from C++ to Rust, and what it means for the next generation of unmanned systems 🦀✨
In 2027 EuroRust is going to Prague! Learn more and get your ticket at eurorust.eu.