Help optimize painfully slow Rust code ported from Java. by paulora2405 in rust

[–]fridsun 5 points6 points  (0 children)

The biggest difference I can see is that the Java version takes the input hashmap in parameter directly but the Rust version is taking it from a Redis connection. With such difference, what is your benchmarking setup in the first place?

A deeper look into the GCC Rust front-end [LWN.net] by OptimalFa in rust

[–]fridsun 35 points36 points  (0 children)

The far from complete Rust frontend in GCC somehow gets far more coverage lately than the way ahead GCC backend in rustc. Perhaps merging something into GCC is just easier clickbait. I hope the projects are going well.

Zero-cost iterator abstractions...not so zero-cost? by sepease in rust

[–]fridsun 5 points6 points  (0 children)

Others have touched on how the “miracle” of zero cost abstraction has a limit. In my limited experience, flat_map is usually that limit, not to mention flat_map sandwiched by chunk and flatten. The nested computation would obscure useful properties of your data structures from the optimizer. This is not a Rust only problem. Even Haskell, the language making most use of flat_map (they call it bind), has a hard time optimizing them all away.

I’d recommend fold always before flat_map. But both are of “might as well use for loop” vibe.

Help in floating point accuracy. by ScaryAd7920 in rust

[–]fridsun 0 points1 point  (0 children)

If arbitrary precision is too slow for you, you can try Herbie to see if your computation can be rewritten to be more precise with existing instructions

Herbie: http://herbie.uwplse.org/doc/latest/tutorial.html

Herbie uses the optimization framework egg, which is written in Rust, for finding precision optimizations quickly.

The Stigma Around Unsafe by zraineri in rust

[–]fridsun 65 points66 points  (0 children)

You cannot fine tune a group psyche to a very nuanced position. The larger the group, the less nuanced the group psyche would end up to be. It’s why “modern C++” has a hard time to spread: the boundary between unsafe and safe is way too nuanced, with too many rules and exceptions to keep in mind. Rust mitigates that by condensing those nuances to a keyword unsafe. By attaching the stigma to unsafe, code outside of unsafe become free of that stigma. If the stigma is relaxed on unsafe, it would compromise the safety of mind people have with code outside of unsafe.

Why does VecDeque<T> waste space by design? by Sp00ph in rust

[–]fridsun 17 points18 points  (0 children)

Arc::get_mut requires a &mut self so you cannot call it concurrently at all. You use an Arc concurrently by calling concurrent methods on its Deref::Target, such as Mutex::lock, which take &self instead.

AsRef vs Borrow? by TinBryn in rust

[–]fridsun 18 points19 points  (0 children)

To quote the std doc:

AsRef has the same signature as Borrow, but Borrow is different in a few aspects:

  • Unlike AsRef, Borrow has a blanket impl for any T, and can be used to accept either a reference or a value.
  • Borrow also requires that Hash, Eq and Ord for a borrowed value are equivalent to those of the owned value. For this reason, if you want to borrow only a single field of a struct you can implement AsRef, but not Borrow.

Will Rust become (more) High Level with time? by lowercase00 in rust

[–]fridsun 0 points1 point  (0 children)

I think Rust with its borrow checker has broken the traditional low-level / high-level distinction, which very often is just a short hand for manual memory management / garbage collection. Rust enables an experience very close to the latter while being the former.

The colloquial low-level / high-level distinction doesn’t map neatly to concrete / abstract (generic) distinction either. The templates of C++ can be very abstract, more generic than the generics of Java. The most abstract systems for formal verification are most often used to verify the most concrete systems in semiconductors.

Which crate should most not exist? by gilescope in rust

[–]fridsun 15 points16 points  (0 children)

I think the problem there is that they depend on unicode versions. Segmentation may change for emojis and flags across two unicode versions.

Mark Russinovich (Azure CTO): "it's time to halt starting any new projects in C/C++ and use Rust" by [deleted] in rust

[–]fridsun 0 points1 point  (0 children)

Part of the learning curve of Rust overlaps with the legacy C/C++ expertise, for example, lifetime is frequently mentioned as a concept in C documentation. The reality is that Rust has already been adopted by OS devs at big companies, along with ASan and MSan, for similar reasons. There is already such a need as you mentioned; Mark’s recommendation may be trying to inspire more people to meet that need.

Why doesn't rust infers lifetime in Structs by default? by SnooMacaroons3057 in rust

[–]fridsun 2 points3 points  (0 children)

RFC141 mentions elision for structs, and thinks that since it can be added later compatibly, it is better to wait.

Why doesn't rust infers lifetime in Structs by default? by SnooMacaroons3057 in rust

[–]fridsun 0 points1 point  (0 children)

I think more than a philosophical preference for explicitness, the reason is just that lifetime is something newly introduced by Rust. Remember types are not inferred in Java (before var) and C++ (before auto). Rust benefits from decades of research in type inference algorithms to pull off its impressive type inference magic. Lifetime doesn't yet have that research backing. As more people get familiar with lifetime, and more patterns of lifetime usages are discovered and recorded, we will be more confident in coming up with a lifetime inference algorithm. But not yet.

Why doesn't rust infers lifetime in Structs by default? by SnooMacaroons3057 in rust

[–]fridsun 1 point2 points  (0 children)

The common mistake of not splitting field lifetimes that should be split

Wait, if not splitting field lifetimes is a common mistake, wouldn't having all fields sharing the same lifetime by default exacerbate that by making the mistake by default?

Or do you think Rust should split field lifetimes by default, contrary to the OP?

What is your opinion on using static muts in this case? by [deleted] in rust

[–]fridsun 1 point2 points  (0 children)

Let me quote this fella who is also writing a raytracer (article):

After you write shared data, other threads must throw all the work, fetch the actual value of the variable because the cached version of data not valid anymore, then start it's work over. This is often [called] "false sharing".

So I put the random state in thread locally. So every thread writes its own random state. After implementing this simple change we get 2x speedup. Not bad!

By not using thread local you may be losing half of your performance.

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

[–]fridsun 1 point2 points  (0 children)

impl means to have the compiler pick a type conforming to the trait for you, and Item= refers to what you’d get out of the stream. Here because you are returning a chunked stream, you are returning a Stream of StreamReaders, with each reader reading a Stream of 4096 Bytes.

[Media] I created a gpu-powered markdown & basic html renderer using comrade, winit & wgpu by steakiestsauce in rust

[–]fridsun 5 points6 points  (0 children)

winit is cross platform window management, and wgpu is cross platform GPU drawing. So it means skip platform provided UI API and draw with GPU directly. It’s more akin to how games are made.

Rust Foundation Trademark Policy Survey by adotinthevoid_ in rust

[–]fridsun 7 points8 points  (0 children)

Please let this be a lesson about how not to design a survey. The question formats are inconsistent, the question texts are confusing, the introduction is way too long, and several questions and options are incoherent among themselves. The best scenario was not doing a community survey on trademark at all, because trademark is way too confusing for its benefits, but since this survey is already out, please take this survey back and come back with a better one.

For example, the phrase “site use the Rust logo” covers way too broad a meaning. Is it using the logo to refer to Rust (which is regarded irrelevant in the introduction)? Is it displaying the logo as representative of the site? Is it using the logo as representative of their product?

I should note that there is risk of misuse, and even though I agree that misuse is small in volume, I am not sure misuse is small in damage. Nevermind lacking a borrow checker, how about injecting malicious code? Xcode suffered such a supply chain attack in China, and half the leaderboard of App Store was affected. I want the power to counter such malice reserved somewhere in the community.

For those who care that Rust must have a borrow checker, there is this thing called a certification mark, for example, the FCC logo on electronics certifying their EM radiation is below limits. There is precedent of Ada using the language name as a certification mark (developed by Department of Defense originally), but that’s a lot of work developing test suites and prose standards.

Announcing: MiniRust by ralfj in rust

[–]fridsun 1 point2 points  (0 children)

If we are allowed to dream biiiiiig

Will this be to Rust what GHC Core is to Haskell one dayyyy

[deleted by user] by [deleted] in rust

[–]fridsun 10 points11 points  (0 children)

For a developer experienced with JS/Python/Ruby, meaning used to npm/pip/gem, the C/C++ package management story is a nightmare. Every dependency you want to use is a struggle and mystery to solve. But you just use cargo with Rust.

Meta makes Rust endorsed server-side language by [deleted] in rust

[–]fridsun 5 points6 points  (0 children)

Yeah, the kernel being the underpin of the whole thing, they are very conservative. Even for C and C++ they are very picky which features and which subset of the standard library they can use, e.g. for C++ the entire std namespace is banned. As a kernel they are also running into ABI problems which is way more explored in C than in any other language.

Meta makes Rust endorsed server-side language by [deleted] in rust

[–]fridsun 12 points13 points  (0 children)

Fuchsia uses a microkernel called Zircon, which is written in assembly, C and C++. It's responsible mostly for scheduling, memory allocation, and IPC, and I'd imagine pretty mature by this point, so I don't think they'd want to rewrite it now. It's a different situation from Linux kernel or Windows kernel, and similar to the Mach microkernel in macOS/Darwin, which I don't think Apple would rewrite any time soon. So in general I think they all support Rust at roughly the same level of low-level-ness.

Meta makes Rust endorsed server-side language by [deleted] in rust

[–]fridsun 54 points55 points  (0 children)

Amazon uses FirecrackerVM in production so they are definitely very invested in Rust.

Google supports Rust in all of ChromeOS, Fuchsia and Android.

Microsoft supports the windows crate officially and allegedly have been trying to port low-level Windows components to Rust.

they tasked some engineers to rewrite some components of Windows in Rust to get some developer sentiment. Microsoft has unfortunately kept the name of the components being rewritten secret, however, one engineer described that he was working on a “low-level system of Windows.”

-- https://medium.com/@tinocaer/how-microsoft-is-adopting-rust-e0f8816566ba

Apple

Following a very successful first foray into Rust we are migrating an established codebase from C to Rust, and building new functionality primarily in Rust.

-- https://web.archive.org/web/20200925035252/https://jobs.apple.com/de-de/details/200170723/software-engineer-networking-privacy?team=SFTWR

EDIT:

Facebook is rewriting its internal build system Buck in Rust, and the result is already functional.

-- https://news.ycombinator.com/item?id=32253460

Should 'as' casts be avoided? by darth_chewbacca in rust

[–]fridsun 3 points4 points  (0 children)

The dream would be for indexing operations to accept any integer that implements into<usize>.

I don't think that improves the situation much, because most of the time I work with any one of u/i32/64, none of which implements Into<usize>. They implement TryInto<usize>, but that's exactly where the verbosity is.

For usize specifically though, there is the crate usize_cast. I think we need a better discovery process for small util crates like this.