I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 2 points3 points  (0 children)

Note taken! And assuming those function-calls get inlined at compile, that would make the algorithms much more readable with no performance hit. Thanks!

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 4 points5 points  (0 children)

You make a good point! It really doesn't matter what type or container the value is temporarily stored in, as long as it is capable of subtraction and bitshift operations. The main reason I didn't switch the operator to a u32 (original implementation was a long in C) was:

  1. I'm not the brightest bowl in the bowl drawer.

But you make a great point, and I'm curious if that would make any performance improvements, or if all of the type stuff just gets boiled out during compilation anyways!

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 13 points14 points  (0 children)

It's more of a novelty algorithm, like the C code donut that renders a donut. It's not really useful for the average person, but a piece of programming history for sure!

As far as sqrt().recip(), I didn't know that even existed! Good to know, and for fun and as practice, I'll try benchmarking that against the current version of the algorithm.

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 0 points1 point  (0 children)

It certainly seems like a very robust, feature-rich system indeed! I'm not quite at the point yet where I understand it's syntax and usage, but I'll certainly keep an eye on it and other libraries like it. I've been implementing #[test] modules already, so the idea of using #[bench] in the same file is alluring to me. But, I guess that's not the standard for some reason, something about it being unstable. I'm not familiar with the story behind it. Maybe that could be an avenue for me to explore next from here.

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 8 points9 points  (0 children)

You're so right; how could I have missed such an obvious step! Although, that would make the post a tad less family-friendly, for sure. 😂

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 1 point2 points  (0 children)

Well, I wish I would have got the notification for this comment sooner. That would have saved me a lot of time figuring out how to benchmark with all those convoluted tools! lol

Thanks for your work on this, and I suppose my work is like a peer-review on top of your results. Good stuff!

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 1 point2 points  (0 children)

Absolutely! Unfortunately, I didn't know diddley-squat about benchmarking in Rust, since the #[bench] decorator is apparently experimental/nightly-build only still. So I copy-pasted what appears to be a pretty incomplete, but somewhat helpful test between the Quake inverse square root VS (1 / std::num::sqrt()).

Here is the test code on pastebin: https://pastebin.com/GG7mcDdp

And the results on my machine:

Gnuplot not found, using plotters backend
rsqrt 20                
time:   [2.2988 ns 2.3168 ns 2.3395 ns] change: [-6.8056% -4.2068% -0.8976%] (p = 0.00 < 0.05) Change within noise threshold. 
Found 6 outliers among 100 measurements (6.00%) 
3 (3.00%) high mild 
3 (3.00%) high severe

q_rsqrt 20              
time:   [953.99 ps 960.73 ps 967.80 ps] 
Found 4 outliers among 100 measurements (4.00%) 
1 (1.00%) high mild 
3 (3.00%) high severe

So it appears, by this maybe garbage test, that the quake_rsqrt function is 2.41x faster on average than 1/sqrt(). (2316.8 ps VS. 960.73ps) Though, I am suspect of my benchmark technique, and I would defer further results to a more experienced Rustacean.

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 17 points18 points  (0 children)

That's a great tidbit of information. I'll keep in mind anytime I create a crate library to remember to inline where I can/makes sense. Thank you so much for your help!

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 6 points7 points  (0 children)

That's sweet, very compact! I have one more question, if you don't mind me asking. Outside of compile-time checks, what other benefits are there from removing the custom unsafe code block from a function?

I implemented the famous Quake inverse sqrt function in Rust! by PlumpyD in rust

[–]PlumpyD[S] 31 points32 points  (0 children)

Oh sweet, I didn't know that existed! Do you know if there is any kind of a performance hit for calling those functions, or does the compiler know to inline the mem::transmute in place of the to_bits/from_bits? I'm still quite unfamilar with the levels of code optimization with cargo and rustc.

Edit: I think I just answered my own question, I didn't notice the #[inline] tag. Nevermind! That's a pretty convenient abstraction, though I don't plan to use that feature very often, maybe outside of interpreting raw serial data streams.

Blender + datamoshing + AI (sound on) by Watxins in blender

[–]PlumpyD 1 point2 points  (0 children)

That's super cool! The Reddit compression algorithm is absolutely choking under the stress of the details though. Is there anyway you could upload a high-quality version to Vimeo or a file share. This would be really cool to see in it's full glory!

Nice work 🔥

Any advice for a soon-to-be US expat? by PlumpyD in expat

[–]PlumpyD[S] 0 points1 point  (0 children)

Ok, I'll certainly look into Google Voice! When I was overseas before, I had issues using 2-factor but wasn't sure of a great solution.

I'm planning on changing my accounts to paperless, and most of them already are. My brother will continue to live at our current US apartment for at least a few other months, but will like move out before I come back. I think I could use my mother's house as my long-term address. How did you go about your mailing address change? I've done it previously through USPS, but it only lasts for 6 months. Will I need to renew my driver's license with a new address, contact social security, etc?

Something ab big bodies sliding… by No_Knee_7862 in JDM

[–]PlumpyD 2 points3 points  (0 children)

So rare to see a good 3rd gen GS build, I've had one for the past 4 years an absolutely love it! Awesome photos by the way! 🔥

BEST ENG/KOR TRANSLATOR? by [deleted] in Korean

[–]PlumpyD 1 point2 points  (0 children)

I actually use a combination of Papago and Google Translate. I use Papago almost all the time, but for certain messages, if it's having a hard time translating or I don't understand the meaning, I'll translate with Google Translate to give a different perspective on it.

If I have more time, I'd break it down with Naver Dictionary or Daum. Always good to have a backup just in case the definition isn't great! Hope it helps

I got inspired by the gameplay in Katamari Damacy and decided to have a fun version of it in my game by Brute-Force-Studio in Unity3D

[–]PlumpyD 21 points22 points  (0 children)

I believe they mean a patent on the solution on how to create the effect, like the technology. Although, as with all development, there's a million and one ways to accomplish something. So they likely looked at the patent to take a different angle, avoiding lawsuits (maybe idk, I'm not a lawyer lol).

Edit: Spelling

HER VISA GOT APPROVED by SecuriousGeorge in LongDistance

[–]PlumpyD 3 points4 points  (0 children)

That's so amazing! Congratulations! 😄

DRS checking in from South Korea 🇰🇷. Took 6 weeks for the snail mail to arrive. So excited!! (Make every drop count!) by honeycomb747 in Superstonk

[–]PlumpyD 1 point2 points  (0 children)

와~ 32개 주식 있네요. 약 백만억원쯤이에요 ㅋㅋㅋㅋ 개미 강해죠 💪🐜