News for hackers. Stuff that matters.
Re:Prepack helps make JavaScript code more efficient by newtonapple on Wednesday May 03, 2017 @03:00PM (#14258957)
What will happen if you have bug in your function? Take the fibonacci function for example, what if you have a bug and created an infinite loop? Will Prepack terminate?
Re:Prepack helps make JavaScript code more efficient by ezekg on Wednesday May 03, 2017 @04:28PM (#14259736)
I was thinking something similar: how does Prepack determine that a function can't be optimized or hits an infinite loop? Seems like the good ol Halting Problem[0].

[0]: https://en.wikipedia.org/wiki/Halting_problem

Re:Prepack helps make JavaScript code more efficient by hinkley on Wednesday May 03, 2017 @05:25PM (#14260271)
The Halting Problem is a bit like Information Theory.

Information Theory, and the Pigeon Hole Principle in specific, says there is no algorithm that can compress all data. That doesn't mean that compression is a fruitless endeavor and we should never have written a compression library.

It means that you have to figure out if your input falls into a subset of data where the outcome of the effort is both tractable and useful. You compress text and structured data, you don't compress noisy data or already compressed data, because it's usually worse than doing nothing.

Similar thing with code analysis. If there is back branching or asynchronous code, you are probably going to hit the Halting Problem, so don't even try. But if the code is linear, then precomputing the output is tractable and useful.

You could also simply apply a budget. If an attempt to unroll a block of code exceeds a certain number of clock cycles or branch operations, you should give up and look at the next most likely scenario. The analysis you're doing might reliably halt in an hour, but who wants to wait that long? Especially when it's one of many such evaluations you'll have to do per build or per day? Just give up and keep moving.

Re:Prepack helps make JavaScript code more efficient by vanderZwan on Wednesday May 03, 2017 @06:46PM (#14260898)
GCC doesn't crash if you tell it to unroll loops with an infinite while loop in your code, does it?
Re:Prepack helps make JavaScript code more efficient by chii on Thursday May 04, 2017 @03:07AM (#14263093)
But you can get into infinite loops with templates!