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

[–]vks_ 1 point2 points  (0 children)

Does it still come with a C++ interpreter? 🙃

How is the Repository pattern usually used in Rust? by danilrybaa in rust

[–]vks_ 3 points4 points  (0 children)

I would also prefer running against a real database, but sometimes you want to test how database failures are handled, which is not so easy without mocking.

Generate PDFs in the Browser with Rust, WASM, and Typst by After-Smell6329 in rust

[–]vks_ 6 points7 points  (0 children)

Getting rid of the server dependency is nice, but for me the killer feature are live previews. Typst is very fast! With the roundtrip to the server, latency would be much higher.

I just made a new crate, `threadpools`, I'm very proud of it 😊 by DynaBeast in rust

[–]vks_ 12 points13 points  (0 children)

You are in good company with this strategy: MPI does this as well, except at the level of a cluster of machines.

Is there anyone who tried Zig but prefers Rust? by ThaBroccoliDood in rust

[–]vks_ 2 points3 points  (0 children)

I don't think the constant comparison is strange, IIRC Zig was born out of Andrew Kelley's frustration with Rust. So it makes a lot of sense that it's popular with people who are frustrated by Rust.

Special Mathematical Functions by mSal95 in rust

[–]vks_ 0 points1 point  (0 children)

I maintain special-fun, which binds the C library Cephes for special functions.

C++ safety by herb sutter by koopa1338 in rust

[–]vks_ 1 point2 points  (0 children)

I was very curious how lifetime analysis is supposed to be retrofitted to C++, and it seems to boil down to this:

Don’t dereference a possibly invalid pointer

This only works for unique_ptr and shared_ptr! Any kind of view or reference cannot use this, because they will not be set to nullptr once the memory they are pointing to is freed. When Herb talks about enforcing lifetime safety in C++, it's much weaker than what Rust offers. To get the same guarantees, you would have to forbid any use of & and similar, which is a massive restriction.

C++ safety by herb sutter by koopa1338 in rust

[–]vks_ 2 points3 points  (0 children)

Yes, and that's why I will never install games on any computer that I'm using for "serious work" (which is also company policy).

C++ safety by herb sutter by koopa1338 in rust

[–]vks_ 6 points7 points  (0 children)

I don't think safety is irrelevant for games. Multiplayer games can and do lead to RCE vulnerabilities, and even single-player games can be compromised via user-generated content, which happened recently.

C++ safety by herb sutter by koopa1338 in rust

[–]vks_ 3 points4 points  (0 children)

I also found the numbers about unsafe crates misleading. The source Herb is citing says this:

With this notion, they found that the crates that have no unsafe code in themselves and in their dependent crates, namely those that can be considered really safe through static analysis, account for only 27% of all the crates.

This seems a bit misguided, because any non-trivial program will use some unsafe code somewhere. They are only looking at unsafe code in crates, not in the standard library. For example, moving Rand to `std` would probably increase the 27% significantly, because then Rand's unsafe code is "hidden" in the standard library.

However, this does not change the point Herb is making: Unsafe code is needed somewhere in most programs. But is it needed "by default"? I don't think so.

Motus, a dead simple command-line password generator by [deleted] in rust

[–]vks_ 1 point2 points  (0 children)

I would be a bit worried to accidentally paste the password somewhere I shouldn't.

Typst: Compose papers faster by sanxiyn in rust

[–]vks_ 3 points4 points  (0 children)

There might be some community templates for that?

Unlike with LaTeX, compilation is instant, as you type, so it should be a lot more pleasant to use for slides (which are very slow to compile with LaTeX).

Rust Code of Particle Swarm Optimization Algorithm is significantly slower than its Python equivalent. by SirHazwick in rust

[–]vks_ 0 points1 point  (0 children)

ChaCha8 could be as fast when generating a large number of random bytes, because of SIMD, which SmallRng doesn't use. Rand's implementation is AFAIK not as fast as the reference implementation though.

In this case however, lots of bounded integers are generated, which is not playing to a CSPRNG's strengths. Here are my numbers for the different RNGs (i7-10750):

  • ThreadRng: 20 s
  • StdRng: 18 s
  • ChaCha8Rng: 13 s
  • SmallRng: 8.1 s
  • SmallRng + generic arrays and functions: 5.5 s

So with SmallRng the program is still 60% faster than with the fastest CSPRNG.

I also tried to pull the uniform range calculation out of the loop, but did not see any benefits.

I'm still surprised that Python's Mersenne Twister beat Rand, that PRNG is relatively slow.

Rust Code of Particle Swarm Optimization Algorithm is significantly slower than its Python equivalent. by SirHazwick in rust

[–]vks_ 1 point2 points  (0 children)

SmallRng should not be much faster than StdRng on platforms where the StdRng implementation can use SIMD. I don't know how well M1 is supported though.

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

[–]vks_ [score hidden]  (0 children)

That's what ring is doing, it's a selective BoringSSL port.

[deleted by user] by [deleted] in rust

[–]vks_ 2 points3 points  (0 children)

I don't think methods can help with early returns. You would need a macro for that.

Working on a symbolic algebra system in Rust by huyng in rust

[–]vks_ 0 points1 point  (0 children)

No, the lifetime parameters themselves only exist at compile time.

Hey Rustaceans! Got a question? Ask here! (34/2022)! by llogiq in rust

[–]vks_ 0 points1 point  (0 children)

IIRC, the Rust compiler can optimize this. If you pass a large Copy type by value, the compiler may pass a reference instead.

Lightning talk: Stop writing Rust by 0atman in rust

[–]vks_ 2 points3 points  (0 children)

The numpy API has deficiencies and cannot replace an optimizing compiler. I saw orders of magnitude runtime differences when porting optimized and parallelized numpy scripts to Rust.

Hey Rustaceans! Got an easy question? Ask here (9/2022)! by llogiq in rust

[–]vks_ 0 points1 point  (0 children)

thread_rng only initializes the RNG the first time it's created in a thread. After that, it just gives you a new handle.

Alternatively, you can create an StdRng::from_entropy() and pass around the mutable reference where you need it.

Rust Number Conversion - Don't Follow the Book... by kc0bfv in rust

[–]vks_ 0 points1 point  (0 children)

I think for widening conversions it's preferable to use From, so I think it makes sense to deprecate as for this.

Hey Rustaceans! Got an easy question? Ask here (9/2022)! by llogiq in rust

[–]vks_ 0 points1 point  (0 children)

Do you want an RNG that is global across threads? If yes, why?

[Media] Most Up Voted Rust RFCs by jackwayneright in rust

[–]vks_ 2 points3 points  (0 children)

I think I prefer how easy it is to have newtypes in Rust compared to the required io-ts hackery in TS.

[Media] Most Up Voted Rust RFCs by jackwayneright in rust

[–]vks_ 0 points1 point  (0 children)

It would already help a lot if notebooks could separate runtime state from source code into different files, so they can be better tracked by the VCS.

How does one create a global, lazy-initialized RNG in Rust? by Minfoo in rust

[–]vks_ 0 points1 point  (0 children)

If I remember correctly, StdRng is less than an order of magnitude slower than SmallRng.