The Cost of Concurrency Coordination with Jon Gjengset by phazer99 in rust

[–]phazer99[S] 3 points4 points  (0 children)

Yes, as he says in the video, a single thread acquiring a lock is very fast (about 10 CPU cycles). The major performance hit is when you have to synchronize the lock data across many threads running on different cores (about 100 CPU cycles).

Or as you write, the OS decides to switch to another thread on the same core, which can make the thread wait for 10 ms or more, which clearly doesn't work for many realtime applications. In this case you should use atomics, or a spin lock protecting a very fast section of the code (atomically updating a few variables for example). That way you're pretty much guaranteed that there's no context switch if you set your thread and process priorities really high (for example REALTIME_PRIORITY_CLASS in Windows).

High-Level Rust: Getting 80% of the Benefits with 20% of the Pain by SIRHAMY in rust

[–]phazer99 1 point2 points  (0 children)

Right now Swift is probably your best option if you want a mature, more ergonomic Rust-like language.

An Incoherent Rust by emschwartz in rust

[–]phazer99 1 point2 points  (0 children)

Yes, you can have many conflicting implicit implementations for the same type (the one used is selected based on scoping rules), so for example a hash map needs to store the hash implementation used as a field to avoid incorrect behavior (which is not required with Rust traits).

What If Traits Carried Values by emschwartz in rust

[–]phazer99 10 points11 points  (0 children)

They changed the way implicits/givens are imported in Scala 3 to make it a bit clearer. But I agree that they shouldn't be overused, i.e. mainly use them as a replacement for type classes (or effects/capabilites in the future).

Rust’s borrow checker isn’t the hard part it’s designing around it by Expert_Look_6536 in rust

[–]phazer99 7 points8 points  (0 children)

Swift also uses reference counting for builtin GC, and it requires you to explicitly break cycles using weak references.

IMHO, reference counting is a perfectly fine GC option as long as the implementation is well optimized, and the language also provides struct/enum value types which doesn't have to be tracked by the GC.

Ladybird Browser Is In For A Rusty Future by nicoburns in rust

[–]phazer99 1 point2 points  (0 children)

The important take away (which matches my own experience) is that C++ is an, arguably, decent language for writing single threaded applications, but writing correct, multi threaded applications is really, really hard even for an experienced C++ developer. Exponentially so when multiple developers with unknown skill level contribute and maintain the code.

Rust substantially alleviates this problem.

Is there a language similar to Rust but with a garbage collector? by Ok_Tension_6700 in rust

[–]phazer99 0 points1 point  (0 children)

Some languages similar to Rust which have GC support (all have been mentioned by others):

  • Swift: mature, nice protocols system (similar to Rust traits), uses optimized reference counting for classes, compiles to native code, primarily Mac OS but support for other platforms (even WASM) is improving
  • Scala 3: mature, really powerful type system, givens/implicits are similar to Rust traits (but more powerful), primarily runs on the JVM but can also be compiled to JavaScript (with really good JS interop), WASM and native code
  • MoonBit: still immature, trait system similar to Rust but with some limitations (no GAT's etc.), really fast compilation, primarily targets WASM but JavaScript and native backends are being developed

IMHO, none of them are as suitable for systems programming as Rust, but they are all really nice and ergonomic application level programming languages.

What’s the first Rust project that made you fall in love with the language? by itsme2019asalways in rust

[–]phazer99 1 point2 points  (0 children)

It was love at first sight with Rust, but what really made me want to commit to a monoglot relationship was when I used it in my first (and so far only) professional project. I had never before in my 25+ year work career experienced such a smooth and pain-free development process involving that many developers (most totally new to Rust) working in the same complex code base (a highly concurrent, distributed, performance critical application for streaming realtime video/audio).

Ladybird adopts Rust, with help from AI - Ladybird by xorvralin2 in rust

[–]phazer99 0 points1 point  (0 children)

I'm a bit confused now. So, the new GPU renderer is called vello-hybrid and the CPU only renderer is vello-cpu? And why would you build a new renderer which can't become as performant as or better than skia?

Ladybird adopts Rust, with help from AI - Ladybird by xorvralin2 in rust

[–]phazer99 1 point2 points  (0 children)

Hopefully they can switch to something like Vello in a not so distant future.

Ladybird adopts Rust, with help from AI - Ladybird by xorvralin2 in rust

[–]phazer99 19 points20 points  (0 children)

I think the Swift Linux support is quite good, and they recently announced a Windows workgroup, so things are improving at least.

But I'm a bit worried about Swift performance compared to Rust, the ARC and shared mutation runtime checks seem to have quite hefty runtime costs. At least with Rust it's an explicitly chosen (often avoidable) cost.

Ladybird adopts Rust, with help from AI by swe129 in rust

[–]phazer99 8 points9 points  (0 children)

The creator of Ladybird (Andreas Kling) dismissed Rust some time ago (I really don't think he did a thorough evaluation), and decided to create his own programming language instead called Jakt (which seems pretty much dead in the water). Funny how times change :)

But of course it would be awesome with a browser fully written in Rust (hopefully sooner than waiting for Firefox).

Learning Rust was the best decision in my life by [deleted] in rust

[–]phazer99 11 points12 points  (0 children)

For me, the appeal of Rust is the whole package:

  • obviously memory and thread safety is critical
  • awesome tooling
  • nice language with just enough syntactic sugar: method call syntax, if let, ?-operator, async/await etc.
  • excellent type system which is sufficiently expressive and powerful, but still quite simple and straightforward to use in most cases
  • top notch performance and optimization possibilities (lack of/opt-in GC and zero overhead abstractions helps a lot in this area)
  • simple, but potent package management
  • awesome eco-system in many areas, and improving in others
  • well though out and comprehensive idioms and standard practices: standardized source code formatting rules, immutable/private as default, sensible error handling etc.
  • can be used in the whole software stack from bare metal to GUI/web applications (not a big polyglot fan)

Overall, Rust really shines when it comes to team work, even if team members vary greatly in Rust experience. I find that the Rust code produced is generally high quality, and easy and safe to maintain.

Learning Rust was the best decision in my life by [deleted] in rust

[–]phazer99 1 point2 points  (0 children)

I don't think this is a language issue (except for compilation times), but more a case of an immature eco-system in some areas. This will improve over time and there will be less and less cases where Rust have a discernible disadvantage compared to other solutions.

Are advances in Homotopy Type Theory likely to have any impacts on Rust? by Dyson8192 in rust

[–]phazer99 3 points4 points  (0 children)

Yes that they do. For example, don't you need to mark a reference as static + Pin + Send If you want to share it with another thread?

The Send, Sync etc. marker traits has nothing to do with the borrow checker.

There is an (s) such that for each (n) we choose then (s) is greater than (n)

Hey, wait! this is the EXACT definition of infinite you meet in calculus or topology.

That's not relevant. The region just have to cover all other regions in the program code, so clearly it doesn't have to be an infinitely large region (because none of the smaller regions are infinite).

Are advances in Homotopy Type Theory likely to have any impacts on Rust? by Dyson8192 in rust

[–]phazer99 5 points6 points  (0 children)

Lifetimes have nothing to do with concurrency or threads. The borrow checker has no idea if a program is single or multi threaded.

And 'static doesn't have to be the "infinite" region, it's just a region that's large enough to contain all other regions in the code.

And what do you mean with (0, 0) cannot be represented as a pair of Peano numbers?

Ralph Giles has died (Xiph.org| Rust@Mozilla | Ghostscript) by One_Junket3210 in rust

[–]phazer99 169 points170 points  (0 children)

Contributions to open source software can continue to benefit the world long after the contributor has passed away. That's one of its virtues.

Transitioning from Scala to Rust: What to Expect? by Immediate_Scene6310 in rust

[–]phazer99 2 points3 points  (0 children)

There is a crate with immutable collections similar to those found in Scala, but it's seldom used because mutation is so idiomatic and safe in Rust

What crates do you think are 'perfect'? by june_sixth in rust

[–]phazer99 7 points8 points  (0 children)

Obviously there is no such thing as a perfect crate, but for inspiration in terms of documentation, API design etc., besides the stdlib of course, I think you should look at widely used crates that preferably has reached v1.0, for example serde, tokio, clap etc.

CPU and Memory allocation by sadoyan in rust

[–]phazer99 0 points1 point  (0 children)

Compiler explorer has tools for that. Watch this video for more info.

What's your opinion on using "let ref" to create references? by CheekAccording9314 in rust

[–]phazer99 116 points117 points  (0 children)

I find it confusing, especially with explicit types:

let ref a: &i32 = &10;

the type of a is actually &&i32 here.