This PR reduces the bundle size of Wonka by 0.15kB minzipped.
It also seems to benefit the micro-benchmarks and hence seems to increase performance (measured using perf/suite.js).
Transpile away Curry._0 and Curry._1 with custom Babel code
This at least passes all uses of urql
The new transpilation turns the Curry application helpers into shorter variants, e.g.:
// This guarantees that only one argument is applied, and the call is otherwise curried
Curry._1(fn, arg1);
// This is simply turned into a ternary:
var _arg1 = arg1,
fn.length === 1 ? fn(_arg1) : fn.bind(null, _arg1)
// And if the ternary isn't actually assigned or used and is just a statement, we can just do:
var _arg1 = arg1,
fn(_arg1)
// This is also done for the other applications with higher arity:
Curry._2(fn, arg1, arg2);
// turns into...
var _arg1 = arg1, _arg2 = arg2,
fn.length === 2 ? fn(_arg1, _arg2) : fn.bind(null, _arg1, _arg2)
This does show the extra vars in the scope, which are created because the arguments may be expressions. But they're minified away if they're not 🤷
This PR reduces the bundle size of Wonka by
0.15kB
minzipped. It also seems to benefit the micro-benchmarks and hence seems to increase performance (measured usingperf/suite.js
).Before:
After:
Changes
makeTrampoline
with inlined codeCurry._0
andCurry._1
with custom Babel codeThis at least passes all uses of
urql
The new transpilation turns the
Curry
application helpers into shorter variants, e.g.:This does show the extra
var
s in the scope, which are created because the arguments may be expressions. But they're minified away if they're not 🤷