Prepack: Prepack hangs

Created on 4 May 2017  路  5Comments  路  Source: facebook/prepack

When given a code that executes for an arbitrary amount of time (potentially forever, such as in the case of I/O or event handling loops), Prepack will take (more than) the full amount of time needed, including potentially forever.

Trivial example:

(function() {
  for (let n = 1; n > 0; n = 1) {}

  let x = 3 + 3;
})();

This will hang Prepack indefinetely - seems like Prepack is _actually_ running the code instead of performing some kind of a static analysis. Why is that? Runnning any non-trivial code in most cases requires a lot of time (esp. if all possible code paths are to be tested), requires environment, state and input/output, including network IO, user interaction, etc. etc.

Is this project some kind of an elaborate joke to teach people about the Halting problem?

Most helpful comment

This will hang Prepack indefinetely - seems like Prepack is actually running the code

It's exactly what it does.

All 5 comments

If prepack hangs on your code, you should definitely not put it into production.

@nifgraup
It might be a game where the main logic loop potentially runs forever until the user stops playing.
Or there might be a loop iterating over third-party data hitting API on each iteration to know if there's more data - could run forever as well.
Or it might just be a long-running background computation; not everything should finish in 100ms, especially on the server side.

This will hang Prepack indefinetely - seems like Prepack is actually running the code

It's exactly what it does.

Prepack is intended to reduce initialization code by evaluating it. If your initialization code is not intended to terminate, then Prepack will not optimize it and probably shouldn't. Put another way, the situations you describe are not things that you could replace with a statically computed result.

You could probably refactor the code such that Prepack doesn't try to optimize that logic by putting it in a callback instead of in the main initialization code. Ideally we would want to add some way in Prepack to deal with that by delaying or abstracting over loops. @hermanventer is working on better Abstract Interpretation for loops.

Check out the timeout option: https://prepack.io/getting-started.html
Otherwise, as others said, it's by design that Prepack runs the global code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matheusml picture matheusml  路  8Comments

aligoren picture aligoren  路  6Comments

NTillmann picture NTillmann  路  8Comments

kamranahmedse picture kamranahmedse  路  7Comments

gaearon picture gaearon  路  5Comments