Edit: Looks like this is targeting compiler output, so Flow types would typically be gone by that stage. Integration with Flow could come via a babel plugin that emits `__assumeDataProperty()` when it encounters a convertible Flow type.
I made a plugin to do this here - https://github.com/codemix/flow-runtime/tree/master/packages...
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.
Just evaluated this:
(function() {
var a = 'a';
var b = [a, 'b', 'c']
.filter((i, index) => i.charAt( 1 - index) !== 'b')
.map(i => i + '!')
.join(',')
console.log(b)
})()
BTW how you avoid going to infinite loops?Having said that, there appears to be a sourceMaps flag in the Prepack source: https://github.com/facebook/prepack/blob/57cc59c07d164e4827c...
I will be attempting to use this as a simple black box, relying on Webpack for features that are only tangentially related to this new optimization stage in my build stack.
I'm a developer currently learning more backend and JS. I hope this question doesn't come out as arrogant. I heard once that "a good compiler should be able to compile itself". Does prepack prepack itself to run faster or can it just for the fun of it? :-)
https://github.com/facebook/prepack/pull/397
Currently it is blocked on Map/Set support in the output which is an outstanding issue. We could also try it with a Map/Set polyfill.
We're very close to being able to though!
In fact, this isn't just Prepack itself but it is Prepacking the JS part of the entire Node.js runtime as well!
In terms of the development status, does the current codebase generally work with React?
I'm happy to throw this at my codebase and report bugs, but whether React itself (which is ~95% of my bundle size) is expected to work (unlike some other optimising products) would say a lot about what the expectation might be.
For instance, a common pattern being:
(function(w) { console.log(w.location); })(window)
This results in issues because it's unaware that window would contain other methods. Is it possible to exclude certain objects in this case?
V8 == user impacted.
Compile time V8 == compiler impacted, users happy.
It's like interpreting what you can during compile time, with caching capabilities.
To speed up boot time and init time, not runtime per say.