News for hackers. Stuff that matters.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by josephg on Saturday December 31, 2022 @03:17PM (#34200308)
Just because we’re on the topic of performance: the rust optimizer can sometimes generate better code if you use map / filter / etc. The slice iterator in any context is a huge win over manual array iteration because it only needs to do bounds checking once.

Javascript (v8, last I checked) is the opposite. Simple for loops almost always outperform anything else.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by duckerude on Saturday December 31, 2022 @05:33PM (#34201437)
I've seen cases where an iterator was better, but I've also seen gains from using an imperative loop with manual indexing. Loop conditions and the occasional assertion can be enough to elide bounds checks. (Though sometimes the compiler gets too paranoid about integer overflow.)

Most of the time you should just write whatever's clear/convenient but sometimes it's worth trying both and scrutinizing godbolt.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by baby on Sunday January 01, 2023 @03:50AM (#34204766)
This is premature optimization imo. Unless you’re using par_iter
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by josephg on Sunday January 01, 2023 @04:41AM (#34205007)
Without knowing the domain, you have no way of knowing that. Eg in the rendering pipeline in the React codebase, I’d be extremely leery of using map/filter/reduce because of how performance sensitive that code is.