Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve List.length performance #1091

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dullbananas
Copy link

No description provided.

to show that it always returns at least one list item even if the string is empty
@harrysarson
Copy link
Contributor

Out of interest: do you have a benchmark?

@dullbananas
Copy link
Author

Out of interest: do you have a benchmark?

I made a benchmark here. It tests a list with 50,000 items.

@harrysarson
Copy link
Contributor

Wow, I see a huge improvement. Looks like by removing the F2 wrappers we get a massive performance gain.

image

var $author$project$Main$currentlength = function (list) {
	return A3(
		$elm$core$List$foldl,
		F2(
			function (_v0, i) {
				return i + 1;
			}),
		0,
		list);
};
var $author$project$Main$lengthHelp0 = F2(
	function (list, acc) {
		lengthHelp0:
		while (true) {
			if (!list.b) {
				return acc;
			} else {
				var xs = list.b;
				var $temp$list = xs,
					$temp$acc = acc + 1;
				list = $temp$list;
				acc = $temp$acc;
				continue lengthHelp0;
			}
		}
	});
var $author$project$Main$newlength = function (list) {
	return A2($author$project$Main$lengthHelp0, list, 0);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants