59
submitted 7 months ago by chrs@programming.dev to c/rust@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] sugar_in_your_tea@sh.itjust.works 15 points 7 months ago

Yup. If that 12-cycle speedup is in a hot loop, then yeah, throw a bunch of comments and tests around it and perhaps keep the "clean" version around for illustrative purposes, and then do the fast thing. Perhaps throw in a feature flag to switch between the "clean" and "fast but a little sketchy" versions, and maybe someone will make a method to memoize pure functions generically so the "clean" version can be used with minimal performance overhead.

Clean code should be the default, optimizations should come later as necessary.

[-] coloredgrayscale@programming.dev 1 points 7 months ago

Keeping the clean version around seems dangerous advice.

You know it won't get maintained if there are changes / fixes. So by the time someone may needs to rewrite the part, or application many years later (think migration to different language) it will be more confusing than helping.

[-] sugar_in_your_tea@sh.itjust.works 5 points 7 months ago

Easy solution: write tests to ensure equivalent behavior.

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

Rust

5989 readers
27 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