Skip to content

Standard library polyfill #293

Closed
Closed
@zloirock

Description

I suggest replace current standard library polyfill (es6-shim & es6-symbol) to core.js. Why?

  • Current polyfill hasn't WeakMap & WeakSet, but we need WeakMap for abstract references. core.js add simple weak-collections polyfill with store values on keys, it doesn't leak and suitable on most cases.
  • core.js add simple module with symbols & methods for abstract references.
  • es6-shim replace native Map & Set in all modern browsers. That, given the performance polyfill, not serious. core.js just fix them.
  • es6-shim Map & Set store data on object chain - lookup time is O(n). core.js Map & Set store data on hash - lookup time is O(1) (but they can't work with frozen objects). Try simple test on native Map, es6-shim and core-js:
var array = [];
for(var i = 0; i < 100000; i++)array.push([{}, {}]);
array = array.concat(array);
console.time('create Map');
var map = new Map(array);
console.timeEnd('create Map');
console.log('Map size: ' + map.size);
// FF34:
// native:                   177.46мс
// es6-shim:                 462863.9мс
// core.js, fixed native:    155.05мс
// core.js, forced replaced: 2287.16мс
  • es6-shim Map & Set doesn't work on IE8-. core.js has fallback for them.
  • es6-symbol generate string key like "@@1", possible conflicts. core.js Symbol generate more complex string key.
  • es6-symbol symbols are enumerable in for-in loop & Object.keys. core.js define setter in Object.prototype - symbols are not enumerable. In the next version I will add an option to disable it.
  • Size: current polyfill browser-polyfill.js size is ~54kb. Custom core.js build with all ES6, ES7 modules, setImmediate (dependence of Promise module) size is:

grunt build:es6,es6_collections,es6_iterators,es6_symbol,es6_promise,es7,es7_refs,immediate uglify
File ./custom.min.js created: 49.43 kB → 15.17 kB → 3.97 kB (gzip)

add ~4.5kb regenerator runtime -> ~19-20kb standard library with much greater capacity than the current. Also you can add another modules or use shim build.

You can try core.js with 6to5 in this simple playground.

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions