Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

TIL, another reason to perform 'defactor inline-method' (with directed feedback of course).


I'm not sure it should be considered as a reason for anything. The most important point of the article, imo, is:

  If a function is only called from a single place, consider inlining it.
You should consider inlining your function, not always do it. Recently, I made a mod for a game and I had to draw an UI by code, and there, it made sens to use one-time function because it made the code easier to read (super-expressive functions like DrawLeftPane() or DrawHeader(), and next to no ties between functions).

Most of the time, code readability should be prioritized over performance.


Totally agree, but in perf critical inner loops, it might be interesting to speculatively inline different functions and measure perf. Overly factored code inside an inner loop has been shown in the video to cause compiler confusion.


People write perf intensive inner loops so infrequently that this really ought to be discounted as an argument.

I work in two performance sensitive projects, both C++, and this has yet to be a reason to inline code. Algorithm choice is optimization of choice first and so far finally.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: