this post was submitted on 08 Apr 2024
59 points (91.5% liked)

Rust

5938 readers
1 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] Turun@feddit.de 7 points 7 months ago (2 children)

It would be interesting to see if an iterator instead of a manual for loop would increase the performance of the base case.

My guess is not, because the compiler should know they are equivalent, but would be interesting to check anyway.

[–] Deebster@programming.dev 2 points 7 months ago (1 children)

I wonder if the compiler checks to see if the calls are pure and are therefore safe to run in parallel. It seems like the kind of thing the Rust compiler should be able to do.

[–] TehPers@beehaw.org 5 points 7 months ago

If by parallel you mean across multiple threads in some map-reduce algorithm, the compiler will not do that automatically since that would be both extremely surprising behavior and in most cases, would make performance worse (it'd be interesting to see just how many shapes you'd need to iterate over before you start seeing performance benefits from map-reduce). If you're referring to vectorization, then the Rust compiler does automatically do that in some cases, and I imagine it depends on how the area is calculated and whether the implementation can be inlined.

[–] onlinepersona@programming.dev 1 points 7 months ago* (last edited 7 months ago) (1 children)

Do you mean this for loop?

for shape in &shapes {
  accum += shape.area();
}

That does use an iterator

for-in-loops, or to be more precise, iterator loops, are a simple syntactic sugar over a common practice within Rust, which is to loop over anything that implements IntoIterator until the iterator returned by .into_iter() returns None (or the loop body uses break).

Anti Commercial AI thingyCC BY-NC-SA 4.0

[–] arendjr@programming.dev 9 points 7 months ago (2 children)

I think they meant using for accumulating, like this:

shapes.iter().map(Shape::area).sum()
[–] Turun@feddit.de 4 points 7 months ago

Yes. That's what I meant.

Though I heavily expect the rust compiler to produce identical assembly for both types of iteration.

[–] onlinepersona@programming.dev 2 points 7 months ago (1 children)

Oh, I see. That would be interesting to benchmark too 👍

Anti Commercial AI thingyCC BY-NC-SA 4.0

[–] sugar_in_your_tea@sh.itjust.works 2 points 7 months ago (1 children)

Anti Commercial AI thingy

Off-topic, but does that actually work? I would assume OpenAI would just ignore it and you'd have to prove that they did so.

[–] onlinepersona@programming.dev 5 points 7 months ago (1 children)

Dunno if it works. AI has been tricked into revealing it's training data, so it's possible that it happens and they are sued for using copyrighted material.

This is my drop in the ocean.

Anti Commercial AI thingyCC BY-NC-SA 4.0

[–] sugar_in_your_tea@sh.itjust.works 2 points 7 months ago (1 children)
[–] onlinepersona@programming.dev 3 points 7 months ago (1 children)

Welcome 🙂 A drop more.

Btw, if you're using linux and X11, you can bind a keyboard shortcut to the following shell-script (probably will need to install xte).

#!/usr/bin/env bash
sleep 0.5
xte "str 
Anti Commercial AI thingy"xte "key Return" xte "str [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)" xte "key Return" xte "str
"

Anti Commercial AI thingyCC BY-NC-SA 4.0

[–] sugar_in_your_tea@sh.itjust.works 3 points 7 months ago (1 children)

I'm on Wayland, but I'm sure I can figure something out.

I do most of my lemmy-ing on mobile, so I'll probably make a bot to auto-edit my posts or something.

[–] onlinepersona@programming.dev 3 points 7 months ago

Have fun! I'm curious how you'll do it. If you figure out a way on Wayland, it would be great to read about it!

Anti Commercial AI thingyCC BY-NC-SA 4.0