Today I was wondering something and couldn't find the answer anywhere: let's say I have a pure function and I'm calling it 2 times in a row with the same parameters, will there be any compiler optimization (or something like that) that will recognize that the function is pure and will cache the result in some ways?
For example, in that code:
const myString = "a,b,c";
console.log(myString.split(","));
console.log(myString.split(","));
Is there anything that will cache the result of the first myString.split(",") and re-use it the second time? I'm assuming that not, because it would require to determine that the function is pure, which could be cumbersome if that function lazy loads something for example, or if the function calls other functions etc...
Thanks!