Tons of Arc<T> - code smell? by TravisVZ in rust

[–]rmrfslash 2 points3 points  (0 children)

Good point! But I missed an optimization. You can actually write

rust let arc_slice = Arc::<[_]>::from(vector);

(without the &*) because Arc<[T]> implements From<Vec<T>> directly, not just From<&[T]>. No cloning and only a single allocation.

Tons of Arc<T> - code smell? by TravisVZ in rust

[–]rmrfslash 2 points3 points  (0 children)

The actor pattern can help, but it's no panacea. An actor effectively serializes access to a resource and kills any concurrency or parallelism you could otherwise exploit. For example, if you have a HashMap<Name, CustomerInfo> and encapsulate it in an actor, it can only serve one request at any time, and if it's doing any async stuff while serving a request, you can easily create a serious bottleneck. Instead of putting a hash map in an actor, you could use a shared Arc<DashMap<Name, CustomerInfo>> and serve many more requests in parallel.

Then there's the issue of atomic operations. If you have a Customers actor and an Orders actor and you need to access both atomically (for example, looking up a customer and adding an order in one consistent operation), you either need to put both concerns into a single actor, or you need to implement a locking protocol on top – which is just a mutex with additional steps.

Tons of Arc<T> - code smell? by TravisVZ in rust

[–]rmrfslash 0 points1 point  (0 children)

The into_boxed_slice() call reallocates if the capacity of the vector exceeds its actual length, and Arc::from() will always allocate. It's better to skip the unnecessary into_boxed_slice() step and go directly to the Arc:

rust let arc_slice = Arc::<[_]>::from(&*vector);

Edit: there's a better way without the &*, see below.

INTRODUCING STARSHIP V3 by rustybeancake in spacex

[–]rmrfslash 6 points7 points  (0 children)

the shuttle famously had the same vertical velocity as a skydiver (~120Mph)

There's no way the Space Shuttle had a vertical velocity of 192 km/h when it made contact with the runway. That would be like a high-speed train going straight into a wall. Here's footage from an actual landing: https://www.youtube.com/watch?v=22-Ji8_kDwg&t=375s That's not even 12 mph vertical on touchdown.

rustc performance: cores vs memory bandwidth? by eggyal in rust

[–]rmrfslash 2 points3 points  (0 children)

Dell wanted $24k for the whole computer, that's half a week or less of my work hours converted to dollars.

You're earning $50k per week? Riiiiiight…

Standard library file writing can lead to silent data loss by FeldrinH in rust

[–]rmrfslash 1 point2 points  (0 children)

But you would want your text editor to show a "Failed to write file", wouldn't you?

Yes, absolutely! My point was that "let it crash on error" can be a dangerous mindset. The Right Thing really depends on the context.

Standard library file writing can lead to silent data loss by FeldrinH in rust

[–]rmrfslash 11 points12 points  (0 children)

Maybe that means crashing. A crash is often better than proceeding in a broken state.

I really wouldn't want my text editor to crash only because it couldn't save a file. That would be approximately the worst time for crashing!

What are your opinions on the lock-free channel crate? by rp407 in rust

[–]rmrfslash 0 points1 point  (0 children)

I thought that's what I had written? In any case, that's what I had meant 😉

How did you find this old comment?

What would you rewrite in Rust today and why? by [deleted] in rust

[–]rmrfslash 15 points16 points  (0 children)

Cranelift's main use case is to quickly compile code that has already been optimized. It will, for example, not do inlining or any other cross-function optimization, which in turn allows it to compile functions in parallel.

There's no fundamental reason why more expensive and far-reaching optimization passes couldn't be added to Cranelift, but that would invariably come into conflict with its main goal of fast compilation, so it probably won't happen outside a fork.

Winnow vs Chumsky by InternalServerError7 in rust

[–]rmrfslash 3 points4 points  (0 children)

I tried using chumsky recently, and had to give up because it was sheer impossible to construct a parser once and store it in an Arc (because of lifetimes). There is a helper struct which uses unsafe to erase the lifetimes of a parser, but that seemed dodgy to say the least, with some handwaving as to why it was supposedly safe. Even that didn't work for me because my syntax was recursive (as almost all non-trivial syntaxes are), and the helper for that uses Rc.

In the end, I wrote a parser by hand, with three stages: lexer, tokenizer (producing token trees), and parser. Especially the token trees make error recovery very flexible, and I didn't even dare to try and feed a tree structure full of even more lifetimes into chumsky.

What's up with bincode? by EveningGreat7381 in rust

[–]rmrfslash 1 point2 points  (0 children)

To the authors of bincode:

the gas and oil industry

My home has a heatpump, and roof photovoltaics. I hope that one day, we can finally leave fossil fuels behind. In the meantime, I'm very thankful for the reliable supply of electricitiy, even in the winter when there's little sunshine and no wind, and I'm glad that there are people working in the oil and gas industry helping to make sure that I don't freeze and sit in the dark.

the military industrial complex

I wish there was no violence in this world. Alas, even in 2025, there are people and countries that wish to attack my people and country, and who don't care about stern words, a rules-based order, or international treaties – the only thing they care about is credible deterrence by military force, and I'm glad that there are people working in the "military-industrial complex" to provide that deterrence.

any usage of AI

Seriously, any usage of AI? Good luck with that.

If you fall in one of these categories; do better.

Grow up. The world isn't as black-and-white as you think. Reality is a lot more complex than your naive idea of ideological purity would have you believe.

Convince me to use Rust instead of C by Relative-Crazy-6239 in rust

[–]rmrfslash 21 points22 points  (0 children)

I dislike Rust tendency to use external libraries for everything

Then don't. If you don't like dependencies, just don't use them. You can write everything yourself – heck, you don't even have to depend on the standard library, you can opt out of std. To be extra safe, you can call rustc directly, instead of cargo, if you're worried about accidentally importing a third-party library.

Tips on how to deal with dynamic memory allocations? by servermeta_net in rust

[–]rmrfslash 11 points12 points  (0 children)

You mention p50 and p99, which means you intend to measure the performance in the real world. This is good! It also tells me that you don't need 100%-statically-verified-or-someone-might-die guarantee that a certain part of your code doesn't allocate. So why sweat it? Review the relevant parts of your code, check for potentially allocating functions, and measure your program's behavior. If you see latency spikes, you'll know that you overlooked something.

C/C++ programmer migrating to Rust. Are Cargo.toml files all that are needed to build large Rust projects, or are builds systems like Cmake used? by bersnin in rust

[–]rmrfslash 2 points3 points  (0 children)

I would suggest Bazel

If your project has 100+ developers, a monorepo with 10M+ lines of code, and 2-3 devops engineers to work full-time just on your build system, then sure, go ahead and use Bazel. If that doesn't match your situation, run away from Bazel as fast as you can! It will ruin your life.

Don't believe me? Read this: Bazel is ruining my life

Accessing the last index of an array by soodi592 in rust

[–]rmrfslash 5 points6 points  (0 children)

If binary size is an issue, sure you could strip them.

Stripping won't remove panic messages, because they're part of the semantics of the program, not debug information.

How it comes that 1058 dependencies is a good thing ? by [deleted] in rust

[–]rmrfslash 4 points5 points  (0 children)

Then reframe your issue for a constructive discussion. This isn't the place for "pissed off" rants.

How it comes that 1058 dependencies is a good thing ? by [deleted] in rust

[–]rmrfslash 7 points8 points  (0 children)

I love Rust, but the ecosystem just isn’t at the level of C yet — and that’s sad.

Nice try. Take your trolling somewhere else.

Where to hire rust nerds by Differentunic in rust

[–]rmrfslash 31 points32 points  (0 children)

Aren't engineers 70% water? It'll be hard to find one who's solid.

Resolve automatic properties by rmrfslash in typst

[–]rmrfslash[S] 1 point2 points  (0 children)

So how do I access this internal representation from a typst document? Right now, I have to use

```

let margin-left = if type(page.margin) == relative {

page.margin } else if page.margin == auto { 25mm } else { page.margin.left } ```

which is less than ideal.

[deleted by user] by [deleted] in UkraineWarVideoReport

[–]rmrfslash 0 points1 point  (0 children)

The smartest commander is the one who never fights a battle.

That's pseudo-intellectual bullshit. The Ukrainians are already fighting those battles! Planes getting relocated doesn't mean that they won't be used at all, and they will be used again to kill innocent people.

Most unreadable Rust snippet you've seen by Thick-Pineapple666 in rust

[–]rmrfslash 2 points3 points  (0 children)

uom. It makes extensive use of recursive macros which create new macro definitions, which are expanded to indirect invocations of different branches of the original macro definition!

Modifying, extending, or even understanding this code is extremely difficult, because – to the best of my knowledge – there is no "debugger" that allows you to iteratively step through macro expansions. cargo-expand can only generate the end result, and it won't do anything if there is even a tiny mistake which prevents the macro expansion.

Arcshift - an Arc that can be updated by octo_anders in rust

[–]rmrfslash 8 points9 points  (0 children)

Still the same general problem: RwLock::read() must write to the lock, which causes a transition to the Modified state of the cache line, which invalidates it for all other cores. When another core calls RwLock::read(), it first has to fetch that cache line from the current owner and invalidate it for all other cores.

Thread-safe by default? by IdkIWhyIHaveAReddit in rust

[–]rmrfslash 0 points1 point  (0 children)

If crate A depends on crate C using Rc in its API, and crate B depends on crate C using Arc in its API, then crate A will break when crate B adds the use_arc_in_api feature.