Skip to content

Navigation Menu

Sign in
Sign up

Improve List.length performance - #1091

Open
dullbananas wants to merge 3 commits into
elm:master from
dullbananas:list-length
Open

Improve List.length performance #1091
dullbananas wants to merge 3 commits into
elm:master from
dullbananas:list-length

Conversation

@dullbananas

@dullbananas dullbananas commented Jul 26, 2020

Copy link
Copy Markdown

No description provided.

adamdicarlo0 reacted with heart emoji
to show that it always returns at least one list item even if the string is empty

Copy link
Copy Markdown
Contributor

Out of interest: do you have a benchmark?

Copy link
Copy Markdown
Author

Out of interest: do you have a benchmark?

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

avh4 and brianvanburken reacted with thumbs up emoji evancz reacted with heart emoji

Copy link
Copy Markdown
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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /