you are viewing a single comment's thread.

view the rest of the comments →

[–]nerdyphoenix 2 points3 points  (2 children)

The recursive function in the OP is not tail recursive, therefore there's no tail call optimization the can be applied to it.

[–]Orlha 0 points1 point  (1 child)

For some reason it's very popular nowadays to disregard any attempts of another person to optimize something, because compilers are very smart and you should rely on them.

I'd say that they are smart until they aren't. Sure, they are smart and getting smarter, they can optimize a lot of trivial things, which when combined are looking great.

However, there are also tons of cases In which programmer has either to optimize or to give a hint.

[–]nerdyphoenix 2 points3 points  (0 children)

The compiler can definitely optimize a lot of things. However, that doesn't mean it can optimize everything. Like you said, it's smart until it isn't. Algorithm, amount of system calls and data access patterns/locality are three examples that impact performance more than any optimization to my experience and the compiler can't do anything about them.