News for hackers. Stuff that matters.
Re:A fun optimization trick from rsync by usefulcat on Sunday October 28, 2018 @10:20PM (#18324530)
An interesting trick, but it seems like there would be a simpler way, like having set_the_mtime be a function pointer. Initially it would point to an implementation that figures out which method works and sets the function pointer to point to a particular implementation.
Re:A fun optimization trick from rsync by beefsack on Sunday October 28, 2018 @11:40PM (#18324889)
Sounds really clever, but also has the potential to be really opaque and confusing. On the other hand, the trick in the article is quite verbose.

Can be tricky balancing terseness with readability.

Re:A fun optimization trick from rsync by usefulcat on Monday October 29, 2018 @12:38AM (#18325100)
> has the potential to be really opaque and confusing

Yes, but.. compared to switch and preprocessor hacks described in the article? Granted it's subjective but I'd find a function pointer that's assigned to once to be way easier to comprehend.

Re:A fun optimization trick from rsync by carlmr on Monday October 29, 2018 @07:30AM (#18326570)
Yeah, I think both methods are somewhat opaque, and the one described here is opaque + hacky. I wouldn't let this through code review.
Re:A fun optimization trick from rsync by Sharlin on Monday October 29, 2018 @05:13AM (#18325983)
I would say that this switch hack is lightyears more "clever" (that is, opaque and confusing) than a simple function pointer.
Re:A fun optimization trick from rsync by ychen306 on Sunday October 28, 2018 @10:52PM (#18324686)
It's more inliner-friendly this way though.
Re:A fun optimization trick from rsync by megous on Sunday October 28, 2018 @11:47PM (#18324914)
No. Compiler can't assume value of switch_step at compile time, so it would have to inline the whole horrid thing every single time.
Re:A fun optimization trick from rsync by corndoge on Monday October 29, 2018 @02:00AM (#18325364)
no guarantee the signatures are the same on all functions, can't use a fp
Re:A fun optimization trick from rsync by jfries on Monday October 29, 2018 @02:05AM (#18325375)
In that case wrapper functions can be created where needed to normalize the signatures.
Re:A fun optimization trick from rsync by bayindirh on Monday October 29, 2018 @07:39AM (#18326615)
Creating signature normalization wrappers, which contain superset of all the function parameters really complicates the code a lot.

It's like trying to push anything and everything through a little hole.

Re:A fun optimization trick from rsync by kochthesecond on Monday October 29, 2018 @12:36PM (#18328833)
Have you heard of our Lord and savior, the single method interface?