amokify icon indicating copy to clipboard operation
amokify copied to clipboard

More performant wrap phase

Open caspervonb opened this issue 9 years ago • 0 comments

The way the current prelude works takes a lot of time because it works in several (redundant) steps

  • Default packer packs everything
  • We have a wrap phase that parses the entire bundle as an AST
  • It then searches through it and finds the module functions
  • Finally it generates a completely new prelude

It also completely destroys any source maps.

If we redesign the prelude ever so slightly.

(function bundle(acquire, cache, entries, modules) {
  function require(name) {
    var updates = acquire();
    Object.keys(updates).forEach(function(key) {
      if (modules[key]) {
        modules[key][1] = updates[key][1];
      } else {
        modules[key] = updates[key];
      }
    });
  }
}(function() { 
  return {
    '0': [function() {
    }, {}]
  };
}, {}, [], {}));

Provided that this works as expected, it should tho as function references are being kept. We should be able to do it in a wrap phase with just some basic string searching in the first and last chunk of the bundle stream. Drastically reducing the overhead of Amokify.

caspervonb avatar Sep 10 '15 00:09 caspervonb