10

I just read https://techfindings.one/archives/2652 about functional programming and came accross this:

anonymous functions can often not be JIT compiled and will never be optimized

Can someone explain to me why this is the case?

  • 1
    see Discuss this ${blog} – gnat Jan 12 '18 at 8:06
  • I think the downvote is not justified here and also the link can't be applied to my question. I'm asking a technical question about JIT and anonymous functions - I'm not asking for opinions/taste or discussion. I'm asking others to explain to me why anonymous functions can't be JIT compiled. Even your link says "I would like others to explain ______ to me”, then you are probably OK" @gnat – thadeuszlay Jan 12 '18 at 8:10
  • 4
    Before you ask "Why?" you should first ask, "Is this even true?". I call BS on that claim. There's 4 different JS engines in the 4 major browsers, and the blanket claim that none of them will optimize anonymous functions, without any reference or data to back that up, is very bold. – Sebastian Redl Jan 12 '18 at 9:06
  • 1
    I am quite certain that at least the V8 engine is certainly able to JIT-compile anonymous functions. Source: I've read related parts of the source code. And there is no technical reason why this should be impossible. So the premise of the question is wrong. This raises the question why the author thinks that statement makes sense. But we can't know that and this isn't the place to discuss it, as explained by gnat's link. – amon Jan 12 '18 at 9:08
  • I see your point and agree with you @SebastianRedl. I didn't understand this statement but instead of digging deeper I did the easy route and asked here. – thadeuszlay Jan 12 '18 at 9:11
15

There is a common misconception about nested functions, named or anonymous, where people think that because the function is declared inside another function, that the compiler must recompile it every time the outer function is invoked. This isn't true. The function's code is constant, even if its calling context isn't, and it can be inlined or optimized just like any other function. This confusion seems especially potent among programmers who primarily use nested functions in interpreted/JIT language implementations, like in this question.

That article has a few other similar misconceptions that show he doesn't understand the issues as well as he thinks he does. I would not consider it a trustworthy source for learning about functional programming.

  • Thanks for clarifying. I'm not an expert in Computer Science (CS) myself. I don't even have a degree or studied CS. Therefore it is hard for me to research everything myself. Could you please clarify what other points the author of the linked article didn't get fully correct? – thadeuszlay Jan 12 '18 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.