mdgriffith / elm-optimize-level-2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimization false negative: inlineWrappedFunctions doesn't work for function aliases

jfmengels opened this issue · comments

The inlineWrappedFunctions transformer transforms

var _String_startsWith = F2(function(sub, str)
{
	return str.indexOf(sub) === 0;
});
-- to
var _String_startsWith_fn = function (sub, str) {
    return str.indexOf(sub) === 0;
}, _String_startsWith = F2(_String_startsWith_fn);

But elm/core's String.startsWith is implemented as startsWith = Elm.Kernel.String.startsWith in Elm (var $elm$core$String$startsWith = _String_startsWith; in JS).

The transformer currently ignores these kinds of functions, meaning that they don't benefit from the same optimization. I think the transformer could try to be smarter by noticing this is an alias to a previously optimized function, and split it up as well.

var $elm$core$String$startsWith = _String_startsWith;
-->
var $elm$core$String$startsWith = _String_startsWith, $elm$core$String$startsWith_fn = _String_startsWith_fn;

and then have the transformer use the most optimized version for the newly optimized functions also.