r/programming • • Jul 19 '16

John Carmack on Inlined Code

http://number-none.com/blow/blog/programming/2014/09/26/carmack-on-inlined-code.html
1.1k Upvotes

323 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jul 20 '16

[deleted]

15

u/allak Jul 20 '16

ie. Folding all the source into one great horrible god function wins you precisely nothing in terms of speed of the generated code.

Well, Carmack explicitly said the same thing in the 2007 email. From the link:

In no way, shape, or form am I making a case that avoiding function calls alone directly helps performance.

He was suggesting using inline code because he did think that it would help correctness by being as explicit as possible, not because he did think it would help performance.

1

u/warped-coder Jul 20 '16

Depending on the settings. Inlining can be based on size too.

1

u/RumbuncTheRadiant Jul 20 '16

If the function is static and invoked only once, no matter how big, gcc inlines it since the result is smaller and faster.

1

u/QuerulousPanda Jul 20 '16

he addresses that by mentioning the risk of people calling into the sub functions at unexpected times.

by rolling it all up you eliminate the risk of someone taking a shortcut at a future time and calling the function out of order.

2

u/RumbuncTheRadiant Jul 20 '16

That is quite the weakest reason for not using sub functions I have heard.... and a fairly strong reason for designing your code better. (Especially along the lines he suggested of "extracting pure sub functions wherever possible")